Improved while loop in Loops.java