O'Reilly logo

Visual C#® 2012: How to Program, Fifth Edition by Harvey Deitel, Paul Deitel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

6.2. Essentials of Counter-Controlled Repetition

This section uses the while repetition statement to formalize the elements required to perform counter-controlled repetition. Counter-controlled repetition 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 whether to continue looping.

To see these elements of counter-controlled repetition, consider the app of Fig. 6.1, which uses a loop to display the numbers from 1 through 10.

 1   // Fig. 6.1: WhileCounter.cs  2   // Counter-controlled ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required