|
Let's show you some examples of the
for (i = 0; i < 10 ; i = i + 1) {
taco[i] = 500;
}
First, in the initializing statement is executed, and i is set
to 0. Then, the loop begins, each time incremented by 1. First, the statement
is "
Let's say we had two arrays of 50 integers,
for (i = 0 ; i < 50 ; i = i + 1) {
chimichanga[i] = burrito[i] + salsa[i];
}
This is much easier than writing out: chimichanga[0] = burrito[0] + salsa[0]; chimichanga[1] = burrito[1] + salsa[1]; chimichanga[2] = burrito[2] + salsa[2]; ... And so on, 50 times!
Hopefully you understand how the
int i;
for (i = (START VALUE) ; i < (END VALUE) ; i = i + 1) {
(LOOP)
}
Which will loop i from (START VALUE) to (END VALUE), each time executing (LOOP). |