Lets assume that you want to repeat something for N times. (We don't care what the "something" is.)
For the loop we want to have a
counter to keep track how many times we have already done the something.
Initialization is what is done before the loop. We set the initial value for the counter. If the counter says how many times the loop's body has already been executed, what should be the value when the loop's body has been executed no times at all?
Condition is an expression that returns bool. It should evaluate to
true
as long as the times we have repeated is less than how many times we want to repeat.
Increment happens after each time the body of the loop has been executed; at the end of each iteration. Since the counter is used here to hold a value that tells how many times the body has been executed so far, it should increment by one after execution of the body.
If you have
1 2 3 4
|
int main() {
// some code
return 0;
}
|
and convert it to:
1 2 3 4 5 6
|
int main() {
if ( init ; cond ; incr ) {
// some code
}
return 0;
}
|
You do achieve the repetition of the
// some code
, if your init, cond, incr are appropriate.
I will not "just type" for you, because you might not reach enlightenment that way. I want you to think.