I am no master at for statements but what they do is run a series of checks essentially.
What this means, in your example is…
for… int (interger value, no decimal) = 1… so starting at 1.
as long as i is < 31… go into the method.
So…
into the method could be… look at all game objects with the tag.player
and reset them to x position.
continue to do this until i = 31.
It’s a basic loop. That is what it’s called: a for loop.
for (int i = 1; i < 31; i++)
{
… do stuff
}
This in english would read like:
loop from 1 to 30.
In code, what is happening is we make a variable called i, and for as long as it is less than 31, we add 1 to i. Obviously, when it it is no longer less than 31 ( <31 ), the loop will terminate.
In C#: for (int i = 1; i < 31; i++)
In javascript: for (var i:int = 1; i<31; i++)
In basic: for i = 1 to 30
In english: loop 30 times, starting with 1
There are many ways to use for loops. Backwards, forwards, multiplied and so on, but the above example is the most common. i usually is just called i because it used to mostly mean the index of an array. You could call it poo if you wanted to:
for (var poo:int = 1; poo<31; poo++)
var poo:int = 1; creates the variable poo and sets it to 1 (in js).
poo<31; check to see if poo is still under 31, if it is then do the following line:
poo++; this means add 1 to poo.
I hope thats clearer. You’ll be best off getting a proper book on c# programming for beginners.
is it true that while running a for loop that
a. no processing goes on in the entire program outside this statement?
b. no programming goes on in this script while running this statement?
c. no programming goes on inside this function while running this statement?
d. none of the above?
A, B and C renman. Its essentially the same as copying and pasting it however many times you run through the loop. Its going to go through the loop until its done and then its going to continue on. It would treat a for to loop that loops through itself a dozen times the same as writing out a dozen print statements individually.
Well, if you read my OP, you’d see that I have, and no one really explained it quite as well as Hippo did. Thank you Hippo! (And everyone else that tried helping me)