IB Statements/ongoto

From CometWiki

< IB Statements
Revision as of 11:03, 20 May 2009 by Badge (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

ON/GOTO statement Syntax: ON numeric-argument GOTO statement-list

Discussion: The ON/GOTO statement transfers program control to a specific statement-label based on the integer portion of the numeric-argument.

The numeric-argument may be a single element numeric variable, a numeric array element, a numeric expression, or a numeric function.

The statement-list contains a minimum of three statement-labels, separated by commas. The integer portion of the numeric-argument determines which statement-label to use, based on a simple set of rules.

If there are only three statement-labels, the rules are:

 Value of numeric-argument   Branch to statement-label
 ===========================================================
 negative                    first statement-label
 zero                        second statement-label
 positive                    third statement-label

If there are more than three labels, they represent positive integer values of the numeric-argument, as follows:

 Value of numeric-argument   Branch to statement-label
 ===========================================================
 negative                    first statement-label
 zero                        second statement-label
 1                           third statement-label
 2                           fourth statement-label
 3                           fifth statement-label
 etc.

Note: If the value of the numeric-argument plus 2 is greater than the number of branch labels in the statement-list, program control is transferred to the last branch label in the list. For example, if the statement-list includes six statement-labels, the sixth label represents the branch-to point for numeric-argument values of 4 and greater.

See GOTO.

Example 1: ON X GOTO 100,200,300,400,500

In the above example, the integer value of the numeric variable X is used to determine where program control will be transferred.

For example, if X is less than zero, program control will be transferred to statement label 100. Likewise, if X equals 0, control will be transferred to statement label 200.

If X equals 1, control will be transferred to statement label 300, and if X equals 2, control will be transferred to statement label 400.

If X is greater than or equal to 3, program control will be transferred to the last statement-label on the list, in this case statement 500.

Example 2: ON CRLIMIT - ARTOTAL GOTO 100,100,200

In this example, the numeric-argument is the expression:

 CRLIMIT - ARTOTAL

The integer portion of this expression is used to determine where program control will be transferred. For example, if the expression yields a negative or zero value (indicating that ARTOTAL is greater or equal to zero), control will be transferred to statement-label 100.

If the expression yields a value of 1 or more, program control will be transferred to statement-label 200.

Personal tools