WHILE...DO loops are used to execute a statement repeatedly while a condition remains true. The WHILE...DO statement is similar to the REPEAT...UNTIL statement except that the condition is checked prior to the initial execution of the statement. See Definition of True and False for details on how the “truth” of an expression is determined.
WHILE expression DO statement
WHILE expression DO BEGIN
i = 10
IDL prints out the numbers 10, 9, ...1.
The following example reads data until the end-of-file is encountered:
The subject statement can also be in the form of a block:
READF, 1, A, B, C
The next example demonstrates one way to find the first element of an array greater than or equal to a specified value assuming the array is sorted into ascending order:
array = [2, 3, 5, 6, 10]
i = 0 ;Initialize index
n = N_ELEMENTS(array)
;Increment i until a point larger than 5 is found or the end of the
;array is reached:
PRINT, 'The first element >= 5 is element ', i
The first element >= 5 is element 2
Tip: Another way to accomplish the same thing is with the WHERE function, which is used to find the subscripts where the array is greater than or equal to X.
P = WHERE(array GE X)
This page has no user notes yet. Be the first one!