Another poster asked about preferred syntax for infinite loops.
A follow-up question: Why do you use infinite loops in your code? I typically see a construct like this:
for (;;) { int scoped_variable = getSomeValue(); if (scoped_variable == some_value) { break; } }
Which lets you get around not being able to see the value of scoped_variable in the for or while clause. What are some other uses for ‘infinite’ loops?
A loop like:
lets you break out of the loop in the middle, rather than at the start (while/for) or end (do-while).
If you’ve got a complex condition, you might also want to use this style to make the code clearer.