[Tutor] break

Matthew Ngaha chigga101 at gmail.com
Fri Mar 15 01:08:11 CET 2013


> 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.

> You could also set a flag and check it at the end of outer loop
> and have a second break statement when the flag is set.
>

im trying to figure out this technique with flags but i havent got it
yet.. what does a flag stand for?


More information about the Tutor mailing list