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.
Visual Basic and Visual FoxPro loops
VBADo While, Do Until, Exit Do, LoopWhile, Wend |
VFPDo While, Loop, Exit, EndDo |
Visual Basic Syntax Notes
Visual Basic has four related types of loop with similar syntax. These run While or Until the test condition is true and allow the test condition to be at the beginning or the end of the loop. A couple of examples:
Do While x < 100
x = x * 2
? x
Loop
or
Do
x = x * 2
? x
Loop Until x >= 100
Use the Loop keyword to skip the rest of the code in the body of the loop and return immediately to the top. Use the Exit Do commands to break out of the loop and execute the statement following the end of the structure.
Visual Basic also has the separate While...Wend structure which has been retained for backwards compatibility with GW-BASIC. This structure has the test at the start of the loop.
Visual FoxPro Syntax Notes
FoxPro just has the loop with While at the beginning so it is not possible to initialise the test condition inside the body of the loop. The test variable must exist and have a value before the loop is entered:
Do While x < 100
x = x * 2
? x
EndDo
Use the Loop keyword to skip the rest of the code in the loop and return immediately to the test in the While statement. Use the Exit command to break out of the loop and execute the statement following EndDo.
FoxPro does have another specialist type of loop command. The scan command is specifically designed for processing data in tables.
Case | Language index | For