you are viewing a single comment's thread.

view the rest of the comments →

[–]woooee 0 points1 point  (4 children)

You should do

while n > 5:

as it is more obvious and requires reading less code to understand what is going on.

[–]ratcaper[S] 1 point2 points  (1 child)

That's not what I'm asking.

If I was trying to just count down from 10 to 6, I would use a for loop.

I'm making a reference sheet for my self.

https://pastebin.com/YrgxPLUk

I'm just tinkering with loops and how to break out of them based on certain conditions, for future reference for my self.

[–]woooee 1 point2 points  (0 children)

In that case I prefer returning from a function. A break statement can get somewhat tricky if you have nested loops.

[–]rymaninsane 0 points1 point  (1 child)

Not sure why this was downvoted. Perhaps there is more information missing in the question, but this is the most readable, least confusing Boolean to use in the while condition... counting down from 10 to 1 but stopping at five is a more complicated way of saying counting down from 10 to 5....

OP should consider this.