Next: The while loop
Up: Unit 06
Previous: Repetition of statements
Conceptually, we distinguish two types of loops, which differ in the way in
which the number of iterations (i.e., repetitions of the body of the
loop) is determined:
- In definite loops, the number of iterations is known before we
start the execution of the body of the loop.
Example: repeat for 10 times printing out a *.
- In indefinite loops, the number of iterations is not known
before we start to execute the body of the loop, but depends on when a
certain condition becomes true (and this depends on what happens in the body
of the loop)
Example: while the user does not decide it is time to stop, print out a
* and ask the user whether he wants to stop.
In Java, like in other programming languages, both types of loop can be
realized through a while statement.
Next: The while loop
Up: Unit 06
Previous: Repetition of statements