python - How can I stop a while loop before it completes the loop -


i'm new python.

i'm having problem 1 class , another. while loop let enemy attack squirtle, or squirtle attack enemy, depending on got first move.

while dead<1:     squirtle.attacked()     squirtle.healthcheck()     enemy1.attacked()     enemy1.healthcheck() 

in each of healthcheck functions asks if enemy or squirtle equal or less 0, if dead=1 , loop should stop. if squirtle dies rest of block still runs; enemy attacked dead squirtle.

i wondering if there way exit block midway through

you should take @ break statement reference

a sample code -

while true:     x = input('input number :')     if x == "1":         break; 

the above code break when input number 1 .

you have adapt program use break statement


Comments

Popular posts from this blog

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -