wrong loop end condition