LOOP and EXIT in repetition structures
Distinguishes skipping an iteration from ending a loop.
Overview
LOOP skips the remaining iteration instructions; FOR still advances its counter and WHILE reevaluates its condition. EXIT transfers after NEXT/ENDDO. Neither automatically returns from the entire function. This example skips 2 and stops before printing 4. In WHILE, advance state before LOOP when needed for termination. (Sources: refs. 1–2.)
Commented example
#Include "Protheus.ch"
User Function Ed703()
Local nItem
For nItem := 1 To 5
// Skip only this iteration.
If nItem == 2
Loop
EndIf
// End FOR without returning from the function.
If nItem == 4
Exit
EndIf
ConOut(nItem)
Next
Return NilDisplays 1 and 3. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Loop exit still requires owned-resource cleanup and task-completion handling.
- Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.