O'Reilly logo

Visual Basic 2005 for Programmers: Deitel Developer Series, Second Edition by Harvey M. Deitel - Deitel & Associates, Inc., Paul J. Deitel - Deitel & Associates, Inc.

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.3. For...Next Repetition Statement

Section 6.2 presented the essentials of counter-controlled repetition with the While statement. Visual Basic also provides the For...Next repetition statement, which specifies the counter-controlled repetition details in a single line of code. To illustrate the power of For...Next, we rewrite the program of Fig. 6.1 using the For...Next statement in Fig. 6.2.

Figure 6.2. Counter-controlled repetition with the For...Next statement.
					1
					' Fig. 6.2: ForCounter.vb
					2
					' Using the For...Next statement for counter-controlled repetition.
					3
					Module ForCounter
 4
					Sub Main()
 5
					' initialization, repetition condition and             
					6
					' incrementing are all included in For...Next statement
					7
					For counter As Integer = 2
						To
						10
						Step
						2                

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