expressão lógicaCondition reevaluated before each iteration. The loop continues only while it returns .T.
AdvPL GuideWHILE <expressão lógica> ... ENDDORepeats a block of commands while a logical expression remains true.
WHILE ... ENDDO evaluates its condition before each iteration. If it is true (.T.), the block runs; when it becomes false (.F.), processing continues after ENDDO. EXIT immediately terminates the loop, while LOOP returns to WHILE and reevaluates the condition without executing the remainder of the current block.
WHILE <expressão lógica> ... ENDDOexpressão lógicaCondition reevaluated before each iteration. The loop continues only while it returns .T.
comandosAdvPL instructions executed on each pass while the condition remains true.
User Function ExWhileEven()
Local nNumber := 0
Local nSum := 0
While nNumber <= 100
nSum += nNumber
nNumber += 2
EndDo
MsgInfo("Sum of even numbers: " + CValToChar(nSum))
ReturnThe condition is checked before each pass. nNumber advances by two until it exceeds 100.
User Function ExWhileTabela()
DbSelectArea("SA1")
SA1->(DbGoTop())
While !SA1->(Eof())
ConOut(SA1->A1_COD + " - " + SA1->A1_NOME)
SA1->(DbSkip())
EndDo
ReturnThe loop processes each record until EOF() indicates the end of the work area. DbSkip() is essential for advancing.
User Function ExWhileControle()
Local nItem := 0
While nItem < 20
nItem++
If nItem % 2 != 0
Loop
EndIf
If nItem > 10
Exit
EndIf
ConOut(CValToChar(nItem))
EndDo
ReturnThe counter is updated before LOOP. Odd values are skipped and EXIT terminates the loop after the desired limit.
© 2026 Usina.BR. All rights reserved. TOTVS, Protheus, Microsiga and their respective logos are trademarks of their owners. AdvPL Guide is independent and uses limited, attributed excerpts justified by educational purposes. See the Terms of Use. Terms of Use
Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.