Home | Previous Page | Next Page   Creating and Using SPL Routines > Writing the Statement Block >

Exiting a Loop

In a FOR, FOREACH, or WHILE loop, you can use a CONTINUE or EXIT statement to control the execution of the loop.

CONTINUE causes the routine to skip the statements in the rest of the loop and move to the next iteration of the FOR statement. EXIT ends the loop and causes the routine to continue executing with the first statement following END FOR. Remember that EXIT must be followed by the keyword of the loop the routine is executing—for example, EXIT FOR or EXIT FOREACH.

Figure 414 shows examples of CONTINUE and EXIT within a FOR loop.

Figure 414.
FOR i = 1 TO 10
   IF i = 5 THEN
      CONTINUE FOR;
. . .
   ELIF i = 8 THEN
      EXIT FOR;
   END IF;

END FOR;

Tip:
You can use CONTINUE and EXIT to improve the performance of SPL routines so that loops do not execute unnecessarily.
Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]