Just need a good old forever loop and a break statement. continue does not break out of loops, replace that statement with break.

Also, the code you just posted sems to be using x and y where it should be using p.x and p.y