Complete the code to create a while loop that runs as long as count is less than 5.
var count = 0 while count [1] 5 { print(count) count += 1 }
The while loop continues as long as the condition is true. Using < means it runs while count is less than 5.
Complete the code to stop the loop when number reaches 10.
var number = 0 while number [1] 10 { print(number) number += 2 }
The loop should run while number is less than 10, so it stops before reaching 10.
Fix the error in the while loop condition to avoid an infinite loop.
var x = 5 while x [1] 0 { print(x) x -= 1 }
The loop should run while x is greater than 0, counting down to stop at 0.
Fill both blanks to create a while loop that prints numbers from 1 to 5.
var num = 1 while num [1] 5 { print(num) num [2] num + 1 }
The loop runs while num is less than or equal to 5. The variable num is updated by assigning num + 1 to it.
Fill all three blanks to create a while loop that prints even numbers from 2 to 10.
var val = [1] while val [2] 10 { print(val) val [3] val + 2 }
Start val at 2. Loop while val is less than or equal to 10. Update val by assigning val + 2.