CASE expressãoCondition evaluated in sequence. The first .T. result selects the block to execute.
AdvPL GuideDO CASE ... CASE <expressão lógica> ... [OTHERWISE ...] ENDCASESelects and executes the first block whose CASE expression evaluates to true.
DO CASE ... ENDCASE organizes decisions with multiple alternatives. CASE expressions are evaluated in order, and only the block associated with the first true (.T.) condition runs. Later conditions are ignored. The optional OTHERWISE clause handles the case in which no CASE is true.
DO CASE ... CASE <expressão lógica> ... [OTHERWISE ...] ENDCASECASE expressãoCondition evaluated in sequence. The first .T. result selects the block to execute.
comandosAdvPL instructions belonging to the selected alternative.
OTHERWISEOptional block executed when every CASE condition returns .F.
User Function ExPeriod()
Local nMonth := Month(Date())
Local cPeriod := ""
Do Case
Case nMonth <= 3
cPeriod := "First quarter"
Case nMonth <= 6
cPeriod := "Second quarter"
Case nMonth <= 9
cPeriod := "Third quarter"
Otherwise
cPeriod := "Fourth quarter"
EndCase
MsgInfo(cPeriod)
ReturnBecause months are tested in ascending order, the first matching limit determines the quarter. OTHERWISE covers the remaining months.
User Function ExPrioridade(nTotal)
Local cFaixa := ""
Do Case
Case nTotal > 100000
cFaixa := "Especial"
Case nTotal > 50000
cFaixa := "Alta"
Case nTotal > 10000
cFaixa := "Média"
Otherwise
cFaixa := "Padrão"
EndCase
Return cFaixaThe highest limit appears first. If the general condition came first, higher tiers would never be reached.
© 2026 Usina.BR. Todos os direitos reservados. TOTVS, Protheus, Microsiga e seus respectivos logotipos são marcas de titularidade da TOTVS S.A. AdvPL é uma linguagem de programação desenvolvida pela TOTVS. O AdvPL Guia é um projeto independente, sem vínculo, representação, patrocínio ou afiliação com a TOTVS S.A., suas franquias ou representantes.