For Loops
A for loop is similar to a while loop, except that the variable on which it depends can be in the scope of the loop.
The syntax is:
for ( DECLARATION/ASSIGN; STATEMENT; EXPRESSION )
Consider:
Code:
int x = 10;
while ( x > 0)
{
--x;
//do things
}
Using a for loop, you do not need a variable outside the loop (although you can still use a variable at a higher scope).
Code:
for (int x = 10; x > 0; --x )
{
//do things
}
That is functionally identical to the while loop.
ZScript for loops are identical to C for loops, so, I suggest reading more on those.
You can, as I mentioned, use an external variable, either with or without an assign in the for loop.
Code:
int x = 10;
for ( x = 5; x > 0; --x) //Changes the value of 'x' to '5' as the loop begins.
int y = 8;
for ( ; y > 0; --y ) //Uses the existing value of y.
That should help you get started.