That should be expected if you consider what the continue command does. As soon as $nick($chan,%i) evaluates to your nick, the code jumps directly back to the top of the loop and the line 'dec %i' is never executed from that point on. Wash, rinse, repeat.