January 2014
Intermediate to advanced
736 pages
70h 43m
English
This section uses the while repetition statement introduced in Section C.7 to formalize the elements required to perform counter-controlled repetition, which requires
1. a control variable (or loop counter)
2. the initial value of the control variable
3. the increment (or decrement) by which the control variable is modified each time through the loop (also known as each iteration of the loop)
4. the loop-continuation condition that determines if looping should continue.
To see these elements of counter-controlled repetition, consider the application of Fig. C.12, which uses a loop to display the numbers from 1 through 10.
1 // Fig. C.12: WhileCounter.java 2
Read now
Unlock full access