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
|