/* Input ten answers in an array, but stop when empty string is entered */ DO n=1 TO 10 PULL My_Variable.n IF My_Variable.n == "" THEN LEAVE END /* Print all integers from 1-10 except 3 */ DO n=1 TO 10 IF n=3 THEN ITERATE SAY n END
If a variable name is placed after the keywords ITERATE or LEAVE, then you can iterate or leave the loop whose control variable is that variable name. This is how, when you have nested loops, you can jump out of an inner loop and skip some of the outer loops -- simply LEAVE or ITERATE to the desired outer loop by placing that outer loop's control variable's name after the LEAVE or ITERATE.
/* Jumping out of an inner loop to an outer loop */ DO loop1=1 TO 3 SAY "I'm in loop1. loop1=" loop1 DO loop2=1 TO 3 SAY "I'm in loop2. loop2=" loop2 DO loop3=1 TO 3 SAY "I'm in loop3. loop3=" loop3 /* Jump out to loop1, thereby skipping loop2's remaining iterations. We jump back to the very first line in this example. */ ITERATE loop1 END END END /* Print pairs (i,j) where 1 <= i,j <= 5, except (2,j) if j>=3 */ DO i=1 TO 5 DO j=1 TO 5 IF i=2 & j=3 THEN ITERATE i /* or "LEAVE j" would work, or just "LEAVE" */ SAY "("i","j")" END END