Database development and training for Birmingham and the midlands
Specialists in Microsoft Access and Visual Foxpro database training and development
I am happy to hear from existing clients but I am taking no new calls.
VFP Tutorial - Do ... While loop
Executes a section of code several times (zero, one or many times) whilst an expression remains true. This example will keep keep adding to a total until that total reaches 100;
lnTotal = 0
Do While lnTotal < lnLimit
*-- Keep adding until we hit the limit
lnTotal = lnTotal + lnNextItem
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 execute.
The code in this example will keep adding new items until the total exceeds the limit.
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 is not an alternative form with the expression being tested at the end of the loop and there is not an inverted form which runs until the expression evaluates as true.
Back to FoxPro program control.