vendredi 8 mai 2015

Python - stopping a while loop issue

I have a while loop in an algorithm:

if Direction == D:
    while maze[x][y][0] and not maze[x][y][1]:
        if (x, y) == (2,2):
            return Output
        y += 1
        Output.append((x, y))
return Output

Which produces a list of tuples and I have to break the function with the return to do so.

However, when I attempt to turn this into some pythonic thing and break it with:

if Direction == D:
    while maze[x][y][0] and not maze[x][y][1]:
        if (x, y) == (2,2):
            break
        y += 1
        Output.append((x, y))
return Output

The terminal won't even return something. Is anyone able to tell why? Am I able to just 'cancel' a loop and move on?

Aucun commentaire:

Enregistrer un commentaire