Control structures and nesting in AdvPL
Identifies which block a loop exit terminates.
Overview
Nested loops require tracking each level’s delimiters. EXIT leaves the loop where it executes rather than returning from the function. The example has two FOR loops, stops the inner one at two and continues the outer loop. Its count demonstrates exit scope without external data. This is a foundation topic despite its historical class label in the queue. (TOTVS, n.d., refs. 1–2)
Commented example
#Include "Protheus.ch"
User Function Ed368()
Local nOuter, nInner
Local nCount := 0
For nOuter := 1 To 2
For nInner := 1 To 3
// EXIT ends only this inner loop.
If nInner == 2
Exit
EndIf
nCount++
Next nInner
Next nOuter
Return nCountExpected return: 2, one counted pass per outer cycle. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Indentation helps inspect scope without replacing ENDIF/NEXT/ENDDO.
- 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.