[Tutor] Exiting a while

Steven D'Aprano steve at pearwood.info
Sat Jul 6 11:48:45 CEST 2013


On 06/07/13 13:33, Jack Little wrote:
> How would I exit a while statement. The while is to keep the player in combat with an enemy until said enemy is dead. I tried using an if, but it just doesn't work.

The devil is in the details, which you do not tell us. How precisely did you use an "if"? Should we guess what you did?

If you did this:

while fighting:
     do combat
     if enemy hit points <= 0:
         print "Hello!"


then naturally it would not work. But if you did this:

while fighting:
     do combat
     if enemy hit points <= 0:
         break


it will. So the real question is, what did you try?



-- 
Steven


More information about the Tutor mailing list