FOR

Syntax | Example | Version History | See Also

The FOR statement executes one or more statements repeatedly, incrementing or decrementing a variable with each repetition, until a condition is met.

Note
For more information on using FOR and other IDL program control statements, see Program Control (Application Programming).

Syntax

FOR variable = init, limit [, Increment] DO statement

or

FOR variable = init, limit [, Increment] DO BEGIN

   statements

ENDFOR

Example

The following example iterates over the elements of an array, printing the value of each element:

PRO ex_for_statement
array = ['one', 'two', 'three']
n = N_ELEMENTS(array)
FOR i=0,n-1 DO BEGIN
PRINT, array[i]
ENDFOR

 

Version History

Original

Introduced

See Also

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