I disagree of "breaking" the while loop by using break
. I think you will always have and "ending condition" and that's what you should aim for. By using break
you are thinking also in not to think about that, although sometimes makes sense for some — I haven't found a single use case where you cannot find a condition to exit.
Using a break
statement in your while
loop is like having the same statements without it, there has to be some logic you are looking for to repeat the statements you want to repeat.
If you give more context you might get a better result. Moreover, a while (true)
is a way to define a infinite loop (something not very useful in real life software).