BEGIN...END

Syntax | Version History | See Also

The BEGIN...END statement defines a block of statements. A block of statements is a group of statements that is treated as a single statement. Blocks are necessary when more than one statement is the subject of a conditional or repetitive statement. For more information on using BEGIN...END and other IDL program control statements, see Program Control (Application Programming).

Syntax

BEGIN

   statements

END | ENDIF | ENDELSE | ENDFOR | ENDREP | ENDWHILE

The END identifier used to terminate the block should correspond to the type of statement in which BEGIN is used. The following table lists the correct END identifiers to use with each type of statement.

Table 4-1: Types of END Identifiers 

Statement
END
Identifier
Example

ELSE BEGIN

ENDELSE

IF (0) THEN A=1 ELSE BEGIN 
   A=2 
ENDELSE 

FOR variable=init, limit DO BEGIN

ENDFOR

FOR i=1,5 DO BEGIN 
   PRINT, array[i] 
ENDFOR 

IF expression THEN BEGIN

ENDIF

IF (0) THEN BEGIN 
   A=1 
ENDIF 

REPEAT BEGIN

ENDREP

REPEAT BEGIN 
   A = A * 2 
ENDREP UNTIL A GT B 

WHILE expression DO BEGIN

ENDWHILE

WHILE ~ EOF(1) DO BEGIN 
   READF, 1, A, B, C 
ENDWHILE 

LABEL: BEGIN

END

LABEL1: BEGIN 
   PRINT, A 
END 

case_expression: BEGIN

END

CASE name OF 
'Moe': BEGIN 
         PRINT, 'Stooge' 
       END 
ENDCASE 

switch_expression: BEGIN

END

SWITCH name OF 
'Moe': BEGIN 
         PRINT, 'Stooge' 
       END 
ENDSWITCH 

Note
CASE and SWITCH also have their own END identifiers. CASE should always be ended with ENDCASE, and SWITCH should always be ended with ENDSWITCH.

Version History

Original

Introduced

See Also

BREAK, CASE, CONTINUE, FOR, GOTO, IF...THEN...ELSE, REPEAT...UNTIL, SWITCH, WHILE...DO, Program Control (Application Programming)