For...Next Statement

<< Click to Display Table of Contents >>

Navigation:  Control Commands >

For...Next Statement

Description

Repeats a group of statements a specified number of times.

Syntax

For counter = start To end [Step step]
    [statements]

    [Exit For]

    [statements]

Next
 

The For...Next statement syntax has these parts:

 

Part

Description

counter

Numeric variable used as a loop counter.

start

Initial value of counter.

end

Final value of counter.

step

Amount counter is changed each time through the loop. If not specified, step defaults to one.

statements

One or more statements between For and Next that are executed the specified number of times.

Exit For

Optional. Transfers control out of the For loop.

Next

Required. Terminates the definition of the For loop.