Previous IDL Reference Guide: Procedures and Functions Next

BEGIN...END

Syntax | Version History

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.

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 3-1: Types of END Identifiers 

Table 3-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

  IDL Online Help (March 06, 2007)