Interpretation of Batch Statements

Each line of a batch file is interpreted exactly as if it was entered from the keyboard. In batch mode, IDL compiles and executes each statement before reading the next statement. This differs from the interpretation of main-level programs compiled using .RNEW or .RUN, in which all statements in a program are compiled as a single unit and then executed.

GOTO statements are illegal in the batch mode because each batch file statement is compiled and executed sequentially.

Multiline statements must be continued on the next line using the $ continuation character, because IDL terminates every interactive mode statement not ending with $ by an END statement. A common mistake is to include a multiple-line block statement in a batch file as shown below.

; This will not work in batch mode. 
FOR I = 1, 10 DO BEGIN 
   A = X[I] 
   ... 
   ... 
ENDFOR 

In batch mode, IDL compiles and executes each line separately, causing syntax errors in the above example because no matching ENDFOR is found on the line containing the BEGIN statement when the line is compiled. The above example could be made to work by writing the block of statements as a single line using the $ (continuation) and & (multiple commands on a single line) characters.