Note: Another way to write an IF...THEN...ELSE statement is with a conditional expression using the ?: operator. For more information, see Working with Conditional Expressions.
Tip: Programs with vector and array expressions run faster than programs with scalars, loops, and IF statements.
The following example illustrates the use of the IF statement using the ELSE clause. Notice that the IF statement is ended with ENDIF, and the ELSE statement is ended with ENDELSE. Also notice that the IF statement can be used with or without the BEGIN...END block:
A = 2
B = 4
PRINT, 'A = ', A
PRINT, 'B = ', B
B != 3
Nesting IF Statements
IF statements can be nested in the following manner:
If condition P1 is true, only statement S1 is executed; if condition P2 is true, only statement S2 is executed, etc. If none of the conditions are true, statement SX will be executed. Conditions are tested in the order they are written. The construction above is similar to the CASE statement except that the conditions are not necessarily related.
IF expression THEN statement [ ELSE statement ]
IF expression THEN BEGIN
ENDIF [ ELSE BEGIN
This page has no comments yet. Be the first one!