Usina BRAdvPL Guide
Sign in
← All topics
COMMANDUnder review

EXIT

EXIT

Ends the current loop and continues after its delimiter.

EXITAdvPL
01 · OVERVIEW

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)

02 · SYNTAX

Syntax

EXIT

Return value

Command without a function return.

03 · PRACTICAL EXAMPLE

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 nSum
Expected result

Expected return: 3. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • 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.

Related content

REFERENCES
  1. TOTVS. EXIT. TDN. Accessed on 2026-10-26.
Status
Under review
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha