Why "if-else-break" breaks in python?

Viewed 37451

I am trying to use if-else expression which is supposed to break the loop if the if condition fails, but getting an invalid syntax error.

Sample code:

a = 5
while True:
    print(a) if a > 0 else break
    a-=1

Of course, if I write in the traditional way (not using the one liner) it works.

What is wrong in using the break command after the else keyword?

3 Answers
Related