Hitachi

JP1 Version 11 JP1/Script Description and Reference (For Windows Systems)


7.1.3 For...Next

Purpose

Flow control statement that iterates a sequence of statements a specified number of times.

Syntax
For Counter = Start To End [Step Step]
  [Statements]
  [Exit For]
  [Statements]
Next
Arguments
Counter

Specify the variable storing the numeric value that is used as the loop counter. Comply with the variable naming conventions. You cannot specify an array variable or an element of an array variable for this variable.

Start

Specify the initial value of Counter.

End

Specify the final value of Counter.

Step

Specify the value by which Counter is incremented at each loop iteration. If you omit the Step argument, 1 will be added to Counter at each loop iteration. You can specify a positive or negative number in Counter. Loop execution is controlled as follows, according to the value you specify in Step.

Value

Execution condition

Positive or zero

Counter [Figure] End

Negative

Counter [Figure] End

Statements

Specify a group of statements to execute in the loop. Write the statements between For and Next. These statements will be executed the number of times specified in For...Next. You can write multiple statements in Statements, with a line return after each one.

Description

When program execution moves to the loop and all the statements in the loop have been executed, the Step value is added to Counter. At this time, if the loop execution condition is satisfied, the statements in the loop are executed again. If the loop execution condition is not satisfied, the program exits the loop and control passes to the statement following the Next statement.

The Exit For statement can only be used within a For...Next or For...End For control structure as a means of exiting a For...Next loop under a condition other than the specified iteration count. You can write any number of Exit For statements anywhere in the For...Next loop. Exit For is often used with the evaluation of some condition (If...Then statement, for example) to pass control to the statement immediately following Next.

You can nest For...Next statements by placing one For...Next within another. When nesting For...Next loops, specify a different variable name in each Counter.

Example
For I = 1 To 10
    For J = 1 To 10
      For K = 1 To 10
        ...
      Next
    Next
Next
JP1/Script version

Supported from JP1/Script 01-00.