Home | Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]

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.

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

Introduced: Original


Home | Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]