Complete the code to print numbers from 1 to 5 using a while loop.
var i = 1 while (i [1] 5) { println(i) i++ }
The while loop continues as long as i is less than or equal to 5, so it prints numbers 1 to 5.
Complete the code to print numbers from 1 to 5 using a do-while loop.
var i = 1 do { println(i) i++ } while (i [1] 6)
The do-while loop runs at least once and continues while i is less than 6, printing 1 to 5.
Fix the error in the while loop condition to avoid an infinite loop.
var count = 0 while (count [1] 5) { println(count) // Missing increment }
The condition should be count < 5 to run the loop 5 times. However, the loop will still be infinite because count is not incremented inside the loop.
Fill both blanks to create a while loop that prints even numbers from 2 to 10.
var num = 2 while (num [1] 10) { println(num) num [2] 2 }
The loop runs while num is less than or equal to 10, and increments num by 2 each time to print even numbers.
Fill all three blanks to create a do-while loop that prints numbers from 10 down to 1.
var i = [1] do { println(i) i [2] 1 } while (i [3] 0)
The loop starts at 10, decreases i by 1 each time, and continues while i is greater than 0, printing 10 down to 1.