Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

LOOP and EXIT in repetition structures

Distinguishes skipping an iteration from ending a loop.

LOOP and EXIT in repetition structuresAdvPL
01 · OVERVIEW

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

03 · PRACTICAL EXAMPLE

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

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

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

Related content

REFERENCES
  1. TOTVS. LOOP. Accessed on 2026-10-28.
  2. TOTVS. EXIT. Accessed on 2026-10-28.
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