For loop condition statement

This is a bit of a silly question, but why does the following not execute the body

1
2
  	for(int i = 0; i ; i++)
		cout << "print " << endl;


i is suppose to be zero, which is true. Doesn't that mean the body should execute.

Its just confusing me because an expression like the following can execute, but the for loop does not.

1
2
3
4
	int num = 2;

	if(num)
		cout << "print" << endl;


for(int i = 0; i ; i++)

Because thats not how for-loops work. You're suppose to tell if how long it should run. If you only want it to run once, then you wouldnt need a for-loop at all would you?
>> i is suppose to be zero, which is true.

i is zero on first iteration, which is false in C++ (false equals zero)
Thanks for the answering the question Kevin C, makes sense now actually.
Topic archived. No new replies allowed.