Usina BRAdvPL Guide
Sign in
← All topics
FOUNDATIONUnder review

Control structures and nesting in AdvPL

Identifies which block a loop exit terminates.

Control structures and nesting in AdvPLAdvPL
01 · OVERVIEW

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)

03 · PRACTICAL EXAMPLE

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

Expected 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.

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

Related content

REFERENCES
  1. TOTVS. Estruturas de controle de fluxo. TDN. Accessed on 2026-10-26.
  2. 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