I just stumbled upon this question Are "while(true)" loops so bad?
They made me think what do I normally do.And to my surprise I realised that I have almost never used a while loop in my professional code(or work code) .
Front end frameworks e.g faces etc do not count.
So When should I use a ‘while loop’? and
How often do you use while loop?
It’s is a real question please do not close as being subjective I really am after a concrete example.where it can not be replaced with a better alternate.
I just stumbled upon this question Are "while(true)" loops so bad? They made me
Share
One place where I might use it is where you need to treat the first element of a sequence differently to the rest. That makes a foreach loop awkward, but a while loop works well:
Also I use a
whileloop as one of the few places where I’ll also include an assignment in a condition:or with an
InputStream: