IF ... ELSEIF ... ELSE ... ENDIF
IF lCond1; ...; ELSEIF lCond2; ...; ELSE; ...; ENDIFChooses a path from sequential logical conditions.
Overview
The first true condition determines the executed block. Optional ELSE covers the remaining case and ENDIF closes the structure. Place specific conditions before general ones to avoid unreachable alternatives. The example classifies a fictional value without applying tax or business rules. (Sources: refs. 1–1.)
Syntax
IF lCond1; ...; ELSEIF lCond2; ...; ELSE; ...; ENDIFCommented example
#Include "Protheus.ch"
User Function Ed483()
Local nQty := 5
Local cState := ""
// Mutually exclusive conditions.
If nQty < 0
cState := "Negative"
ElseIf nQty == 0
cState := "Zero"
Else
cState := "Positive"
EndIf
ConOut(cState)
Return NilSelects the positive alternative. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Avoid side effects in conditions and validate types before comparing.
- 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.