Chapter 14. Statement Reference
195
____________________________________________________________________
Flow control statement
FOR…NEXT
Defines a loop containing statements to be executed a specified number of times.
____________________________________________________________________
Syntax:
Syntax:Syntax:
Syntax:
FOR controlvariable = initialvalue TO finalvalue [STEPincrement]
-
-
-
NEXT [controlvariable]
Parameter:
Parameter:Parameter:
Parameter:
controlvariable
A non-array numeric variable.
initialvalue, finalvalue, and increment
Numeric expressions.
Description:
Description:Description:
Description:
FOR…NEXT defines a loop containing statements (which is called "body of a loop")to be
executed by the number of repetitions controlled by initialvalue,finalvalue, and
increment.
Processing procedures
(1) The Interpreter assigns initialvalue to controlvariable.
(2) The Interpreter checks terminating condition; that is, it compares the value of
controlvariable against the finalvalue.
- When the value of increment is positive:
If the value of controlvariable is equal to or less than the finalvalue,go to step
(3). If it becomes greater the finalvalue, the program proceeds with the first line
after the NEXT statement (the loop is over).
- When the value of increment is negative:
If the value of controlvariable is equal to or greater than the finalvalue,go to
step (3). If it becomes less than the finalvalue, the program proceeds with the first
line after the NEXT statement (the loop is over).
(3) The body of the loop executes and the NEXT statement increases the value of
controlvariable by the value of increment. Then, control returns to the FOR
statement at the top of the loop. Go back to step (2).
Comentários a estes Manuais