Problem with if/else

Take a look at where your loop function actually ends.