Previous IDL Reference Guide: Procedures and Functions Next

FOR

Syntax | Examples | Version History

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.

Syntax

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

or

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

   statements

ENDFOR

Examples

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

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

Version History

Original
Introduced

  IDL Online Help (March 06, 2007)