-
For loops can be equivalent to while loops. But you really should prefer while loops unless your iterations are counted.
I certainly prefer
while(1)
to
for(;;)
Also while loops tend to lead to more readable code but thats probably just personal preference.
-
Loop zealots annoy me. Use the best tool for the job you're doing. Each loop is made for specific types of behavior, and you should use whatever fits your current purpose, not whatever fits your religious beliefs.
-
It is just about personal preference.
Bohn Jacopini proved that EVERY loop can be made just with while() and eventually break statements so do<% %>while() and for(;;) are unneeded.
But as Fol said, every of them have a purpose.
while() initial check.
do<% %>while() final check.
for(;;) + break central check.
for(e;e;e) initial statement, final check, final statement.
About good style Stroustrup says (if I recall correcly) that he prefere, sorted by most favourite:
for(;;) because make life easier when you need final and initial check.
while() if you do not need initial and final statement it puts the condition right there.
do<% %>while() if you need final check