Standing in front of a printer, you give it an instruction to print pages with indexes 2 to 16 from your book. The printer, which is programmed to do so, uses an algorithm to print pages for you; it checks for the document and the number of pages you asked to print. It sets the starting point as 2 and the last point as 16, and it starts printing till the last point is reached. Printing pages we can call repetitive, thus printing each page from your document can be well programmed using a looping construct. As in any other language, Scala supports for, while, and do while loops.
Take a look at the following program:
object PagePrinter extends App {
/*
* Prints pages page 1 to lastIndex for doc
*/
def printPages(doc: Document, lastIndex: Int) = ??? //Yet to be defined
/*
* Prints pages page startIndex to lastIndex for doc
*/
def printPages(doc: Document...