IF...THEN...ELSE
Syntax | Examples | Version History | See Also
The IF...THEN...ELSE statement conditionally executes a statement or block of statements.
Note
For information on using IF...THEN...ELSE and other IDL program control statements, see Program Control (Application Programming).
Syntax
IF expression THEN statement [ ELSE statement ]
or
IF expression THEN BEGIN
statements
ENDIF [ ELSE BEGIN
statements
ENDELSE ]
Examples
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 IF (A EQ 2) AND (B EQ 3) THEN BEGIN PRINT, 'A = ', A PRINT, 'B = ', B ENDIF ELSE BEGIN IF A NE 2 THEN PRINT, 'A <> 2' ELSE PRINT, 'B <> 3' ENDELSE
IDL Prints:
Version History
See Also
BEGIN...END, BREAK, CASE, CONTINUE, FOR, GOTO, REPEAT...UNTIL, SWITCH, WHILE...DO, Program Control (Application Programming)