dimanche 11 juillet 2021

Python: How to execute statement and break in same line?

I am currently working on a coding competition that requires the least amount of characters used to accomplish a task. I have many if statements in it which are in a while loop, and each one requires a break statement. Currently, my code is:

while <something>:
   if <something> is <something>:
      <do this>
      break

to shorten this I can do:

while <something>:
   if <something> is <something>:<do this>

But according to my knowledge, I can't break after this. Is there any way to break and execute a statement in the same line?

Aucun commentaire:

Enregistrer un commentaire