Complete the code to print numbers from 1 to 5 using a while loop.
int i = 1; while (i [1] 5) { System.out.println(i); i++; }
The condition i <= 5 ensures the loop runs while i is 1 through 5.
Complete the code to stop the loop when the variable count reaches 10.
int count = 0; while (count [1] 10) { System.out.println(count); count++; }
The loop should run while count is less than 10, so count < 10 is correct.
Fix the error in the while loop condition to avoid an infinite loop.
int x = 5; while (x [1] 0) { System.out.println(x); x--; }
The condition x >= 0 ensures the loop runs while x is 5 down to 0, avoiding infinite loop.
Fill both blanks to create a while loop that prints even numbers from 2 to 10.
int num = 2; while (num [1] 10) { System.out.println(num); num [2] 2; }
The condition num <= 10 includes 10, and num += 2 increases num by 2 each time.
Fill all three blanks to create a while loop that counts down from 15 to 5 by 2.
int val = [1]; while (val [2] [3]) { System.out.println(val); val -= 2; }
Start at 15, loop while val is greater than or equal to 5, counting down by 2.
