Usina BRAdvPL Guide
Sign in
← All topics
COMMANDUnder review

LOOP

LOOP (FOR ... NEXT / WHILE ... ENDDO)

Skips the remainder of a FOR or WHILE iteration.

LOOPAdvPL
01 · OVERVIEW

Overview

In FOR the counter advances normally; in WHILE the condition is reevaluated. Placing WHILE progress after LOOP can cause endless repetition. Unlike EXIT, LOOP does not terminate the loop. (Sources: refs. 1–1.)

02 · SYNTAX

Syntax

LOOP (FOR ... NEXT / WHILE ... ENDDO)

Return value

Flow control; no returned value.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed512()
    Local nI
    For nI := 1 To 5
        // Skip only iteration number 3.
        If nI == 3
            Loop
        EndIf
        ConOut(cValToChar(nI))
    Next
Return Nil
Expected result

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

BEST PRACTICES
  • Ensure required progress and cleanup occur before skipping an iteration.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. LOOP. TDN. Accessed on 2026-10-27.
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