Complete the code to create a loop that runs while i is less than 5.
package main import "fmt" func main() { i := 0 for [1] { fmt.Println(i) i++ } }
The condition i < 5 makes the loop run while i is less than 5.
Complete the code to print numbers from 1 to 3 using a for loop as while.
package main import "fmt" func main() { i := 1 for [1] { fmt.Println(i) i++ } }
The condition i <= 3 makes the loop run while i is 1, 2, and 3.
Fix the error in the loop condition to run while count is less than 4.
package main import "fmt" func main() { count := 0 for [1] { fmt.Println(count) count++ } }
The condition count < 4 runs the loop while count is 0, 1, 2, and 3.
Fill both blanks to create a loop that prints numbers from 2 to 6.
package main import "fmt" func main() { num := 2 for [1] { fmt.Println(num) num [2] } }
The condition num <= 6 keeps the loop running until 6. The increment num++ increases num by 1 each time.
Fill all three blanks to create a loop that prints even numbers from 0 to 4.
package main import "fmt" func main() { i := 0 for [1] { fmt.Println(i) i [2] 2 } }
The condition i <= 4 runs the loop while i is 0, 2, and 4. The operator += adds 2 to i each time.
