Jul 13, 2012 at 10:41pm UTC
DetectiveRawr wrote:"What does "for (int i=1; i<5; i++)" mean?"
It's a loop.
i is a variable that's local to the loop; it's initialised to 1. While the value of
i is less than 5,
i is incremented by 1 after the body of the loop is executed. It's equivalent to:
1 2 3 4 5 6 7 8 9 10
{
int i_(1);
while (i_ < 5)
{
/*
* ...
*/
++i_;
}
}
See here: http://www.cplusplus.com/doc/tutorial/control/#for
Wazzak
Last edited on Jul 13, 2012 at 10:43pm UTC
Jul 13, 2012 at 11:57pm UTC
Hmmm thank you. I haven't reach the part about loop yet. I'm at the beginning lol.
Jul 14, 2012 at 12:21am UTC
It looks like you're rushing ahead of yourself. Slow down, son.
Wazzak
Jul 14, 2012 at 12:23pm UTC
Is it really normal to declare a variable integer inside a for loop?
Jul 14, 2012 at 12:26pm UTC
Yes, but you don't have to declare anything either. In fact, you can declare any type of variable/object.
Wazzak
Jul 23, 2012 at 11:15pm UTC
Well I learned about variables and now I"m at the control structure which is chapter 2.