VFP Tutorial - Do While ... EndDo loop
The Do While ... EndDo loop in FoxPro executes a section of code several times
whilst an expression remains true. The loop may execute zero, once or many times.
This example will keep keep adding to a total until that total reaches 100;
lnLimit = 100
lnTotal = 0
Do While
lnTotal <
lnLimit
lnTotal =
lnTotal +
lnNextItem
Print
lnTotal
EndDo
If the expression
lnTotal <
lnLimit evaluates as true
(.T. in FoxPro)
then the statements in the loop will be executed and the
expression will be evaluated again. The loop will continue
until the expression evaluates as false
(.F. in FoxPro).
If the expression evaluates as false when FoxPro first reaches
it then the statements inside the body of the loop will never
be executed.
Notes
The test condition must evaluate as .T.
or .F. because the logical values in
FoxPro are a separate data type and an integer result will not be
interpreted as a logical value.
This is the only form of the while loop in Foxpro. There are no
alternative forms with the expression being tested at the end of the
loop or with the logic inverted so that the loop runs until the expression
evaluates as true.
Back to FoxPro
program control.
Introduction |
Environment |
Project |
Tables |
Forms |
Navigation |
Executable
|