|
|
|
|
|
by munificent
4259 days ago
|
|
Really? I use "while (true)" pretty frequently in my code. In my mind, all loops are composed of these parts: 1. Some initialization (optional).
2. Some stuff you do each iteration (optional).
3. Check the exit condition and exit the loop (optional).
4. Some stuff you do each iteration (optional). "while" loops nicely handle the case where 2 is empty. "do while" loops handle 4 being empty. "for" loops handle both 2 and 4 being non-empty but only really accommodate 4 being a single expression. For any other case where 2 is non-empty and 4 is more than a single expression, I just use a "while (true)" with an "if (...) break;" in the body. |
|
[0] Or utterly catastrophic. Think embedded system with limited debugging facilities. This kind of bug could manifest as the system completely locking up, and take much, much longer to track down than a "infinite loop detected!" message in an error log.