Challenge - 5 Problems
Go Continue Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of loop with continue skipping even numbers
What is the output of this Go program?
Go
package main import "fmt" func main() { for i := 1; i <= 5; i++ { if i%2 == 0 { continue } fmt.Print(i, " ") } }
Attempts:
2 left
๐ก Hint
The continue statement skips the rest of the loop body for even numbers.
โ Incorrect
The loop prints numbers from 1 to 5. When the number is even, continue skips printing it. So only odd numbers 1, 3, and 5 are printed.
โ Predict Output
intermediate2:00remaining
Continue statement inside nested loops
What will this Go program print?
Go
package main import "fmt" func main() { for i := 1; i <= 2; i++ { for j := 1; j <= 3; j++ { if j == 2 { continue } fmt.Printf("%d%d ", i, j) } } }
Attempts:
2 left
๐ก Hint
Continue skips printing when j equals 2, but only for the inner loop.
โ Incorrect
The inner loop skips printing when j == 2, so it prints j=1 and j=3 for each i. So output is 11 13 21 23.
โ Predict Output
advanced2:00remaining
Effect of continue in a range loop over a slice
What is the output of this Go program?
Go
package main import "fmt" func main() { nums := []int{1, 2, 3, 4, 5} sum := 0 for _, n := range nums { if n%2 == 0 { continue } sum += n } fmt.Println(sum) }
Attempts:
2 left
๐ก Hint
Only odd numbers are added to sum because continue skips even numbers.
โ Incorrect
The loop adds only odd numbers: 1 + 3 + 5 = 9. Even numbers are skipped by continue.
โ Predict Output
advanced2:00remaining
Continue statement with label in nested loops
What will this Go program print?
Go
package main import "fmt" func main() { Outer: for i := 1; i <= 3; i++ { for j := 1; j <= 3; j++ { if j == 2 { continue Outer } fmt.Printf("%d%d ", i, j) } } }
Attempts:
2 left
๐ก Hint
Continue with label skips to next iteration of the outer loop when j == 2.
โ Incorrect
When j == 2, continue Outer skips the rest of inner and outer loop body and moves to next i. So only j=1 prints for each i: 11 21 31.
๐ง Conceptual
expert1:30remaining
Why use continue statement in Go loops?
Which of the following best explains the purpose of the continue statement in Go loops?
Attempts:
2 left
๐ก Hint
Think about what happens when you want to skip some work but keep looping.
โ Incorrect
The continue statement skips the rest of the current loop iteration and proceeds with the next iteration. It does not exit the loop or restart it.