Fix problem with `continue` in for loop in while loop