The arithmetic IF statement conditionally transfers control to one of three statements, based on the current value of an arithmetic expression. It takes the following form:
IF (e) s1,s2,s3
All three labels (s1,s2,s3) are required, but they do not need to refer to three different statements.
The arithmetic IF statement first evaluates the expression e. It then transfers control to one of the three statement labels in the transfer list, as follows:
If the value of e is | Control passes to |
---|---|
Less than 0 | Label s1 |
Equal to 0 | Label s2 |
Greater than 0 | Label s3 |
The first example transfers control to statement 50 if the real variable THETA is less than or equal to the real variable CHI. Control passes to statement 100 only if THETA is greater than CHI.
IF (THETA-CHI) 50,50,100
The second example transfers control to statement 40 if the value of the integer variable NUMBER is even. It transfers control to statement 20 if the value is odd.
IF (NUMBER/2*2-NUMBER) 20,40,20