Does for( ; test for
expr !=0 or expr == 0?
Chad
Does for( ; test for
expr !=0 or expr == 0?
Chad
Well, for(;; ) is technically always true, so it doesn't matter. But in general, conditional tests by default test for != 0. That's why
Executes the block if x isn't 0.Code:if ( x ) { /* Stuff */ }
probably depends on the compiler, but VC++ 2005 Express does not make any tests, it just creates an infinite loop with a jump at the bottom back to the top of the loop. No test is necessary. As if you had written this:
Code:int main() { loop: // do some code here goto loop; }
Last edited by Ancient Dragon; 01-20-2006 at 10:34 PM.
The C Standard says that an "omitted expression-2 is replaced by a nonzero constant", where expression-2 refers to the expression that controls the for loop.
So you might say that it tests for expr == 1, but then the wording of the standard is effectively "leaving out expression-2 creates an infinite loop", so no comparison is actually required in the first place.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)