EXIT
EXITEnds the current loop and continues after its delimiter.
Overview
EXIT leaves WHILE/ENDDO or FOR/NEXT before normal completion. The function continues after the loop: it differs from RETURN and transactional BREAK. Here the condition precedes summation; when the counter reaches three, the sum remains 1+2. Statement order expresses the rule rather than mere formatting. (TOTVS, n.d., ref. 1)
Syntax
EXITReturn value
Command without a function return.
Commented example
#Include "Protheus.ch"
User Function Ed375()
Local nIndex
Local nSum := 0
For nIndex := 1 To 5
// Exit before including the first out-of-scope value.
If nIndex == 3
Exit
EndIf
nSum += nIndex
Next nIndex
Return nSumExpected return: 3. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Review nested-loop scope and keep resource cleanup after the exit.
- 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.