I have made the change suggested by VladimirF and also the if statement 4 lines below and now the loop will not execute at all, the program freezes with a flashing cursor.