next Statement

The next statement occurs at the end of a for...next construct and causes the iteration counter to increment and branches to the corresponding for statement to decide whether to terminate.

Syntax

for var = exp to exp {step exp}

statement{s}

next var

Description

The for...next construct can also be exited using the exit clause.

The step clause allows the increments of the loop to be changed. For example, step 2 increments the variable by 2 when the next statement is encountered.

step can be a negative number, decrementing the variable at the next statement. A step of 0 does not execute the for...next loop.

Example(s)

In this example:

for i = 1 to 10

crt i:" ":

next i

print

the output result would be the following:

1 2 3 4 5 6 7 8 9 10

In this example:

numbers = ’’

for i = 1 to 2

for j = 1 to 5

numbers<i,j> = j

next j

next i

print numbers

The output result would be the following:

1]2]3]4]5^1]2]3]4]5

In this example:

for j = 10 to 1 step -1

print j:" ":

next j

print

The output result would be the following:

c10 9 8 7 6 5 4 3 2 1om

See Also

continue Statement

for...next Statement