Name
For . . . Next Statement
Synopsis
Forcounter
=initial_value
Tomaximum_value _
[Step stepcounter]'code to execute on each iteration
[Exit For] Next [counter
]
counter
required (optional withNext
statement); any valid numeric variableA variable that serves as the loop counter
initial_value
required; any valid numeric expressionThe starting value of
counter
for the first iteration of the loopmaximum_value
required; any valid numeric expressionThe value of
counter
during the last iteration of the loopstepcounter
optional (required ifStep
is used); any valid numeric expressionThe amount by which
counter
is to be incremented or decremented on each iteration of the loop
Description
Defines a loop that executes a given number of times, as determined by a loop counter.
To use the For...Next
loop, you must assign a
numeric value to a counter variable. This counter is either
incremented or decremented automatically with each iteration of the
loop. In the For
statement, you specify the value
that is to be assigned to the counter initially and the maximum value
the counter will reach for the block of code to be executed. The
Next
statement marks the end of the block of code
that is to execute repeatedly, and it also serves as a kind of flag
that indicates that the counter variable is to be modified.
Get VB.NET Language Pocket Reference 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.