6.4. Examples Using the For...Next Statement
The following examples demonstrate different ways of varying the control variable in a For...Next statement. In each case, we write the appropriate For...Next header.
Vary the control variable from 1 to 100 in increments of 1.
For i = 1 To 100 or For i = 1 To 100 Step 1
Vary the control variable from 100 to 1 in increments of -1 (decrements of 1).
For i = 100 To 1 Step -1
Vary the control variable from 7 to 77 in increments of 7.
For i = 7 To 77 Step 7
Vary the control variable from 20 to 2 in increments of -2 (decrements of 2).
For i = 20 To 2 Step -2
Vary the control variable over the sequence of the following values: 2, 5, 8, 11, 14, 17, 20.
For i = 2 To 20 Step 3
Vary the control variable over ...
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.