The best is to study the statements from a c / c++ reference since they are exactly the same as for Angelscript
Here's one of millions of good references
http://www.java2s.com/Tutorial/C/0120__Statement/Thewhileloop.phpHere's a quick overview of the for, and the while
For: The for loop is used to itterate over a series of instructions,
and uses a step value to increase the base counter
The base counter is a variable, usually an int, and the letter i is
ofter used, from the original c documentation
for(i=start; i < end; i = i + step){
//do something
}
example:
for(i=0; i<20; i++){ //use i base, start counting from 0, while i is less than 20, and increase base i by step 1
}
example:
for(i=0; i<40; i+2){ //use i base, start counting from 0, while i is less than 40, and increase base i by step 2
}
example:
for(i=30; i<0; i--){ //use i base, start counting from 30, while i is greater than 30, and decrease base i by step 1
}
i++ means i += 1
i-- means i -= 1
If you use a break inside the for loop, it will exit the loop at that point
If you use a continue inside the for loop, it will skip the rest of the instructions in the
for loop, and start with the next step increment
example:
for(i=0; i<20; i++){
n+=i;
m = n*3;
if(m == 16){
break; //the for loop will exit and terminate here, going onto the instruction after the close of the loop
}
p = m/(n+1); //this will be skipped
q = p+2; //this will be skipped
}
for(i=0; i<20; i++){
n+=i;
m = n*3;
if(m == 16){
continue; //the lines below will be skipped, and the loop will continue with the next step value if i
}
p = m/(n+1); //this will be skipped
q = p+2; //this will be skipped
}
while: Is similar to for, except that it does not havea base or a step counter
You need to make sure that a condition is met in order to finalize the while loop
example:
int i = 0; //start with some value
while(i < 10){ //while i is smaller than 10, do everything in the block, if i is = 10, then exit the loop
i++;
//do something
}
The break statement also works inside a while loop, and exits the loop when used
Refer to c documentation for more detail and info this and on on "switch-case"