I have to agree with sbi here - I like the middle-checking loop term. This kind of construct was more popular when Structured Programming started to roll and many languages had syntactic support for them.
That said, it is now widespread knowledge that while
loops are usually more mantainable, since it is easier to reason about invariants and they often handle the tricky empty case better.
In your particular case your loop is just equivalent to
for(; doSomething(), !condition(); doSomethingElse()){}
so I would only use the break
version if either doSomething
or doSomethingElse
involved multiple statements and I'd rather not put them away into separate functions like you did.
That said, if your loop is more complicated then a (start, check, increment) iteration then you should consider refactoring it into something simpler.
condition()
always returns false? I'd say it's an infinite loop with conditional breaks.break
, the loop is not infinite (kill
, ctrl-alt-del, unplug...). So why bother with terminology details?