| Home | Previous Lesson: Arrays Next Lesson: Continue Statement |
The EXIT statement causes the innermost enclosing loop to exit immediately. It has a very simple syntax:
EXIT
Because it causes a loop to exit, this statement is legal only if it appears within one of loop statements such as DO�LOOP, FOR�NEXT. In loops, it is typically used to exit prematurely when, for whatever reason, there is no longer any need to complete the loop. When a loop has complex termination conditions, it is often easier to implement some of these conditions with EXIT statements, rather than trying to express them all in a single loop expression. The following code searches the elements of an array for a particular value. The loop terminates naturally when it reaches the end of the array; it terminates with a EXIT statement if it finds what it is looking for in the array:
li_TotalItems = UpperBound(ls_Array)
FOR i = li_TotalItems Step 1
IF ls_Array[i] = "Xyz" Then
EXIT
END IF
NEXT
| Home | Previous Lesson: Arrays Next Lesson: Continue Statement |