bug fix in while loop generation