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 > 5 else break
a-=1
Of course, if I write in the traditional way (not using the one liner) it works.
Please let me know what is wrong in using the break
command after the else
keyword.
Aucun commentaire:
Enregistrer un commentaire