Control-flow structures
Combines sequence, decisions and loops with an explicit condition.
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)
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 nSumExpected 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.
- 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.

Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.