The ON statement allows selective execution of procedural statements on a periodic basis.
General Format
Syntax Rules
- Identifier-1, identifier-2 and identifier-3 must describe unsigned integer numeric elementary items.
- Literal-1, literal-2 and literal-3 must be unsigned numeric literals.
- The ON statement is not supported in class programs when compiling to
JVM COBOL code.
General Rules
- Prior to the first execution of each ON statement , a counter, implicitly defined for that ON statement (the implicit-ON-counter),
is initialized to be zero.
- Identifier-1, identifier-2 and identifier-3 should, if specified, contain positive integer values at the time of execution
of the ON statement. Varying these values between executions of the ON statement will affect subsequent executions of the
ON statements.
- The implicit ON counter cannot be affected in any way other than by transfer of execution flow to that ON statement. (The
ON counter of a called program can only be reset by the canceling of that program; execution of the EXIT PROGRAM statement
and subsequent CALL of the program without intervening CANCEL has no effect upon the implicit ON counter value.)
- The following value-list is then evaluated:
- The current value of identifier-1 or literal-1,
- A sequence of values being the results of repeatedly adding the current value of identifier-2 or literal-2 to the current
value of identifier-1 or literal-1 until the value of identifier-3 or literal-3 is reached.
The implicit-ON-counter is then compared with each of this list of values. If an equality is found, then imperative-statement-1
is executed. If no equality is found, then imperative-statement-2, if specified, is executed.