Infinite while loop vs for loop

May 19, 2013 at 1:17am
Why is it that in a infinite while loop you must add a true but in a for loop you can leave it empty?

Is it just how C++ works or any reason?
May 19, 2013 at 1:50am
IIRC, The standard specifically says that for (;;) is a valid way to write an infinite loop. Otherwise it wouldn't make much sense (since the empty statement does not evaluate to anything).

The while statement has no exception to normal constraints, requiring a valid expression (not a statement) that can be resolved to a boolean value in parentheses.

The infinite loop thing is just a shortcut (less to type) found in the original language. No other reason.

Hope this helps.
May 19, 2013 at 1:53am
Alright thanks!
Topic archived. No new replies allowed.