Get rid of nasty infinite loop in while example