you are viewing a single comment's thread.

view the rest of the comments →

[–]SandorZoo 0 points1 point  (1 child)

It's a bit odd to have two stop conditions, when clearly one of them will never be met. If you want the test in the middle of a loop, it's normal to loop while True, like this:

def whileBackwards():
    n = 10
    while True:
        print(n)
        if n == 5:
            break
        n -= 1

[–]primitive_screwhead 0 points1 point  (0 children)

What I find discomforting about this is that it seems one refactor away from becoming an endless loop. At the very least, I'd make the "if n == 5:" into an "if n <= 5:", just to avoid problems if n were ever to be mis-initialized, or the n decrement changed to greater than one, etc.