What is the best way to write a loop with no body
c++
Solution
I think option B is most commonly used, but you should make it more obvious that you have an empty loop body:
while (func())
; // do nothing
or
while (func()) { /* do nothing */ }
As a side note, this looks like some kind of busy waiting. If this is the case, it can and should usually be avoided by using OS-provided synchronization primitives.
Problem
I have a function `func` which returns `true` or `false`. Until `func` returns `false`, I want to keep calling it. What is the least awkward way to do this? ``` do { // do nothing } while (func()); ``` or.. ``` while (func()); ``` or.. ``` while (func()) if (!func()) break; ``` All of them look really awkward and unintuitive to me. Is there another solution to this altogether?