VFP Tutorial - For ... Next loop

This program structure executes a section of code several times. The number of repetitions is controlled by a counter which changes each time that the loop executes. By default, th ecounter increases by 1 on each iteration:

lnLimit = 10
For lnCount = 1 To lnLimit
   * Print the numbers from 1 to lnLimit inclusive
   Print lnCount
Next lnCount

This loop will execute ten times and will print the numbers from one to ten. Use a for loop whenever you know how many times the loop has to execute. Use a do...while loop if you need a loop that will run until it meets some final criterion.

Notes

It is possible to programmatically change the counter value within the loop but this usually leads to code with subtle bugs.

The Next lnCount marking the end of the structure can be replaced by EndFor but you may find it easier to use the Next option because it is the same form as in Visual Basic and Access.

Back to FoxPro program control .


Introduction | Environment | Project | Tables | Forms | Navigation | Executable

MS Access technical tips

Visual FoxPro technical tips

General Tips

 

More tips from Alvechurch Data

Visual FoxPro Tutorial - The Goto statement

The truth about the FoxPro Goto statement

Read More

Visual FoxPro Tutorial - If ... Else ... EndIf

Using If EndIf to control program flow in Visual FoxPro

Read More

Visual FoxPro Tutorial - Navigation

Navigating between records in Visual FoxPro

Read More

Visual FoxPro Tutorial - Scan ... EndScan loop

Using a scan loop to control program flow in Visual FoxPro

Read More

Visual FoxPro Tutorial - Variables

Using variables in Visual FoxPro

Read More