REPEAT...UNTIL
REPEAT...UNIL loops are used to repetitively execute a subject statement until a condition is true. The condition is checked after the subject statement is executed. Therefore, the subject statement is always executed at least once. (See Definition of True and False for details on how the "truth" of an expression is determined.)
The syntax of the REPEAT statement is as follows:
or
Examples — REPEAT...UNTIL
The following example finds the smallest power of 2 that is greater than B:
The subject statement can also be in the form of a block:
The next example sorts the elements of ARR using the inefficient bubble sort method. (A more efficient way to sort elements is to use IDL's SORT function.)
;Sort array. REPEAT BEGIN ;Set flag to true. NOSWAP = 1 FOR I = 0, N - 2 DO IF arr[I] GT arr[I + 1]THEN BEGIN ;Swapped elements, clear flag. NOSWAP = 0 T = arr[I] & arr[I] = arr[I + 1] & arr[I + 1] = T ENDIF ;Keep going until nothing is moved. ENDREP UNTIL NOSWAP