Complete the code to print numbers from 1 to 3 using a loop.
for i := 1; i <= [1]; i++ { fmt.Println(i) }
The loop runs while i is less than or equal to 3, printing numbers 1, 2, and 3.
Complete the code to sum numbers from 1 to 4 using a loop.
sum := 0 for i := 1; i <= 4; [1] { sum += i } fmt.Println(sum)
i-- which decreases the variable and causes an infinite loop.The loop variable i increases by 1 each time to add all numbers from 1 to 4.
Fix the error in the loop to print numbers from 1 to 5.
for i := 1; i < [1]; i++ { fmt.Println(i) }
i < 5 which stops before printing 5.Using i < 6 makes the loop print numbers 1 to 5 because it stops before 6.
Fill both blanks to create a loop that prints even numbers from 2 to 8.
for i := [1]; i <= [2]; i += 2 { fmt.Println(i) }
The loop starts at 2 and goes up to 8, increasing by 2 each time to print even numbers.
Fill all three blanks to create a loop that prints numbers from 10 down to 6.
for i := [1]; i [2] [3]; i-- { fmt.Println(i) }
<= instead of >= in the condition.The loop starts at 10 and decreases by 1 until it reaches 6, printing numbers 10 to 6.
