Skip to main content

4.3) Conditional Blocks


If in the previous example we want statement 1 and/or statement 2 to consist of more than one statement, then we need to use a BEGIN and ENDIF:

IF condition THEN BEGIN
   statement 1a
   statement 1b
   statement 1c
ENDIF

The statements between a BEGIN and an END are called a block of statements. These can only be used within programs/functions/procedures and not at the IDL command line.

IF condition THEN BEGIN
   statement 1a
   statement 1b
   statement 1c
ENDIF ELSE BEGIN
   statement 2a
   statement 2b
   statement 2c
ENDELSE