Visual Basic and Visual FoxPro For Next loops


For, Step, Exit For, Next


For, Step, Loop, Exit, Next, EndFor

Common Syntax Notes

This is another structure where there is very similar syntax in the two languages.

For i = 1 To 10
  ? i
Next i

FoxPro used to end the structure with an EndFor but Visual FoxPro now accepts the VBA syntax Next clause as an alternative:

Both languages also have a For Each structure for working with arrays and collections.

Use the Loop keyword to skip the rest of the code in the FoxPro loop and return immediately to the test in the For statement. Use the Exit command to break out of the loop and execute the statement following Next.

Loops  |  Language index  |  Procedures