Game Development Community

For loop

by Jamal Moon · in Technical Issues · 02/03/2008 (9:56 pm) · 2 replies

Can someone please explain what the for loop does or when you use it? I usually see something like this...
for(%i=0; %i < 7; %i++)
{
   .....

Also, what would you do with %i after you made the for loop?
thanks

#1
02/03/2008 (10:38 pm)
Well it's simple programming.

%i=0 - it initialized the variable %i to zero.
%i < 7 - Is our variable less then 7? This determine is the loop is done again or not.
%i++ - amount to add to our variable each loop.

in this example whatever code is in the for loop, will be repeated 7 times.

there's no need to do anything with %i as it is a local variable and is deleted after the function is run.
#2
02/04/2008 (2:32 pm)
Thanks alot! This clears up a bunch of stuff for me.