6.2. Essentials of Counter-Controlled Repetition

This section uses the While repetition statement introduced in Chapter 5 to highlight the elements required to perform counter-controlled repetition. Counter-controlled repetition requires

  1. the name of a control variable (or loop counter) that is used to determine whether the loop continues to iterate

  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

  4. the condition that tests for the final value of the control variable (i.e., whether looping should continue)

The example in Fig. 6.1 uses the four elements of counter-controlled repetition to display the even integers in the range 2–10. The declaration in line 5 ...

Get Visual Basic 2005 for Programmers: Deitel Developer Series, Second Edition 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.