For loops in C# and VFP

C#

For

VFP

For, Step, Loop, Exit, Next, EndFor

Both FoxPro and C# have loops which will run for a certain number of iterations but the syntax is very different.

C# Syntax Notes

The C# loop starts with the for and this is followed by three expressions in brackets:

for (int i = 1; i < 10; i++)
  {
  Console.WriteLine(i);
  }

In this example:

  • the first expression initialises the loop counter to 1
  • the second expression controls the loop, running so long as i is less than 10
  • the third expression increments the counter by 1 at each iteration

Note that the loop counter i has been declared inside the loop control structure. It cannot be accessed from any code outside of the structure.

VFP Syntax Notes

Visual FoxPro uses the same syntax as Visual Basic. Original versions of FoxPro used to end the structure with an EndFor but VFP now accepts the same Next clause as VBA.

for i = 1 to 10
  ? i
next i

Visual FoxPro also has a For Each structure for working with arrays and collections.

Loops  |  Language index  |  Procedures

MS Access technical tips

Visual FoxPro technical tips

General Tips

 

More tips from Alvechurch Data

Site Map

Site map of the Alvechurch Data site

Read More

VFP and C#.

C# is very different from Visual FoxPro so conversion from one language to the other is difficult.

Read More

Comments in C# and VFP

Adding comments to programs in C# and Visual FoxPro

Read More

Constants in C# and VFP

Declaring constants in C# and Visual FoxPro

Read More

Variables in C# and VFP

Declaring variables in C# and Visual FoxPro

Read More