[Tutor] break

Mitya Sirenef msirenef at lightbird.net
Fri Mar 15 01:24:29 CET 2013


On 03/14/2013 08:08 PM, Matthew Ngaha wrote:
>> One good approach is to  have a separate function or method with
 >> both loops:
 >>
 >> def attack(self, Enemy):
 >>
 >> for missile in self.missiles:
 >> for rect in Enemy.rects:
 >> if QPoint(missile.x + 5, missile.y) in rect:
 >> explosion = Explosion(rect.x(), rect.y())
 >> self.explosions.append(explosion)
 >> return
 >
 > i altered this because once it returns the outer loop also stops and i
 > need it incase i have more than 1 missile to loop through. i made it
 > so i did the outer loop in the program and sent the inner loop to this
 > function, but for some reason the code seems to break my program.. no
 > errors are returned but it just freezes on inputs and missile
 > collision.


Sorry, reading failure on my part. The code you had originally should
break properly. You can add assert(not flag) as Dave suggested to figure
out what actually happens. Maybe you have more than one instance of the
same missile?

   -m



-- 
Lark's Tongue Guide to Python: http://lightbird.net/larks/

Children begin by loving their parents; after a time they judge them;
rarely, if ever, do they forgive them.  Oscar Wilde



More information about the Tutor mailing list