March 26th, 2013, 07:49 AM
The second fragment executes "statements" once, then loops indefinitely doing nothing (except hogging CPU cycles). The semi-colon in that context is a "null statment" - a do nothing.
A better idiom for an indefinite loop is:
Some compilers will issue an "expression is always true" or similar warning for "while(1)" or "while(true)", but will not for "for(;;)".
As ever, the better way to answer your question would be to a) run the code, b) step the code in your debugger. You should not have got as far as while loops in programming without learning to use a debugger. It will save you having to ask this sort question with answers of varying quality.
Last edited by clifford : March 26th, 2013 at 07:52 AM.