5.2 Essentials of Counter-Controlled Repetition
This section uses the while repetition statement introduced in Chapter 4 to formalize the elements required to perform counter-controlled repetition, which requires
-
a control variable (or loop counter)
-
the initial value of the control variable
-
the increment (or decrement) by which the control variable is modified each time through the loop (also known as each iteration of the loop)
-
the loop-continuation condition that determines if looping should continue.
To see these elements of counter-controlled repetition, consider the application of Fig. 5.1, which uses a loop to display the numbers from 1 through 10.
Get Java How to Program (early objects), 9/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.