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. The step clause can be a negative number, decrementing the variable at the next statement. A step of 0 does not execute the for...next loop.

The var is optional. It is typically used for code clarity, but is ignored by the compiler.

Example(s)

Example 1

for i = 1 to 10
   crt i:" ":
next i
print

Example 1 output result:

1 2 3 4 5 6 7 8 9 10

Example 2

numbers = ’’
   for i = 1 to 2
      for j = 1 to 5
         numbers<i,j> = j
      next j
   next i
print numbers

Example 2 output result:

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

Example 3

for j = 10 to 1 step -1
   print j:" ":
next 
print

Example 3 output result:

10 9 8 7 6 5 4 3 2 1