break

break does not break out of "ifs", only loops. Your break leaves the while loop.