Usina BRAdvPL Guide
Sign in
← All topics
FOUNDATIONUnder review

Control-flow structures

Combines sequence, decisions and loops with an explicit condition.

Control-flow structuresAdvPL
01 · OVERVIEW

Overview

Documentation groups sequence, conditional branching, repetition and multiple branching. Choose the structure for the rule: IF selects a path while FOR visits a known interval. This example sums only values above one, with movement controlled by FOR itself. Local variables avoid dependence on a global counter. No table access or transactional effects occur. (TOTVS, n.d., ref. 1)

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"
User Function Ed367()
    Local nIndex
    Local nSum := 0
    // The condition selects values within the interval.
    For nIndex := 1 To 3
        If nIndex > 1
            nSum += nIndex
        EndIf
    Next nIndex
Return nSum
Expected result

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

BEST PRACTICES
  • Define start, condition and movement for every loop.
  • 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.
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