Bird
Raised Fist0
Goprogramming~10 mins

Continue statement in Go - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to skip printing the number 3 in the loop.

Go
for i := 1; i <= 5; i++ {
    if i == 3 {
        [1]
    }
    fmt.Println(i)
}
Drag options to blanks, or click blank then click option'
Acontinue
Bgoto
Cbreak
Dreturn
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using break will exit the loop entirely.
Using return will exit the function, not just skip iteration.
2fill in blank
medium

Complete the code to skip even numbers when printing from 1 to 6.

Go
for i := 1; i <= 6; i++ {
    if i%2 == 0 {
        [1]
    }
    fmt.Println(i)
}
Drag options to blanks, or click blank then click option'
Abreak
Bcontinue
Cexit
Dstop
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using break will stop the entire loop early.
Using exit or stop are not valid Go statements.
3fill in blank
hard

Fix the error in the loop to skip printing negative numbers.

Go
numbers := []int{2, -1, 3, -4, 5}
for _, num := range numbers {
    if num < 0 {
        [1]
    }
    fmt.Println(num)
}
Drag options to blanks, or click blank then click option'
Areturn
Bbreak
Ccontinue
Dskip
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using break will stop the loop completely.
Using skip is not a valid Go statement.
4fill in blank
hard

Fill both blanks to skip printing numbers divisible by 3 in the loop.

Go
for i := 1; i <= 10; i++ {
    if i [1] 3 == 0 {
        [2]
    }
    fmt.Println(i)
}
Drag options to blanks, or click blank then click option'
A%
Bbreak
Ccontinue
D==
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using break will stop the loop entirely.
Using == instead of % will cause a logic error.
5fill in blank
hard

Fill all three blanks to skip printing words shorter than 4 letters and convert others to uppercase.

Go
words := []string{"go", "code", "fun", "learn"}
for _, word := range words {
    if len(word) [1] 3 {
        [2]
    }
    fmt.Println([3])
}
Drag options to blanks, or click blank then click option'
A<=
Bcontinue
Cstrings.ToUpper(word)
D==
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using == instead of <= will miss some short words.
Printing word without conversion does not meet the requirement.

Practice

(1/5)
1. What does the continue statement do inside a loop in Go?
easy
A. Skips the rest of the current loop iteration and moves to the next iteration
B. Stops the entire loop immediately
C. Exits the current function
D. Repeats the current iteration without moving forward

Solution

  1. Step 1: Understand the role of continue in loops

    The continue statement tells the loop to skip the remaining code in the current iteration.
  2. Step 2: Identify what happens after continue

    After skipping, the loop moves on to the next iteration without stopping the whole loop.
  3. Final Answer:

    Skips the rest of the current loop iteration and moves to the next iteration -> Option A
  4. Quick Check:

    continue skips current step [OK]
Hint: Remember: continue skips current step, not whole loop [OK]
Common Mistakes:
  • Confusing continue with break
  • Thinking continue exits the function
  • Assuming continue repeats the iteration
2. Which of the following is the correct syntax to use continue inside a for loop in Go?
easy
A. continue
B. continue {}
C. continue()
D. continue;

Solution

  1. Step 1: Recall Go syntax for statements

    In Go, continue is a keyword used alone without parentheses or semicolons.
  2. Step 2: Identify the correct form

    The correct usage is simply continue by itself inside the loop.
  3. Final Answer:

    continue -> Option A
  4. Quick Check:

    Go statements like continue have no parentheses or semicolons [OK]
Hint: Use continue alone, no parentheses or semicolon needed [OK]
Common Mistakes:
  • Adding semicolon after continue
  • Using continue as a function with parentheses
  • Using braces {} after continue
3. What will be the output of the following Go code?
for i := 1; i <= 5; i++ {
    if i == 3 {
        continue
    }
    fmt.Print(i, " ")
}
medium
A. 1 2 3 4 5
B. 1 2
C. 3 4 5
D. 1 2 4 5

Solution

  1. Step 1: Analyze the loop and condition

    The loop runs from 1 to 5. When i equals 3, continue skips printing 3.
  2. Step 2: Determine printed values

    Values 1, 2, 4, and 5 are printed with spaces. Number 3 is skipped.
  3. Final Answer:

    1 2 4 5 -> Option D
  4. Quick Check:

    continue skips printing 3 [OK]
Hint: Skip printing when continue hits condition [OK]
Common Mistakes:
  • Including 3 in output
  • Stopping loop instead of skipping
  • Printing nothing due to misunderstanding continue
4. Identify the error in this Go code snippet using continue:
for i := 0; i < 5; i++ {
    if i == 2 {
        continue()
    }
    fmt.Println(i)
}
medium
A. The loop condition is incorrect
B. fmt.Println is used incorrectly
C. Using parentheses with continue causes a syntax error
D. continue should be replaced with break

Solution

  1. Step 1: Check the usage of continue

    In Go, continue is a statement without parentheses. Using continue() causes a syntax error.
  2. Step 2: Verify other parts

    The loop condition and fmt.Println usage are correct. The error is only in the continue syntax.
  3. Final Answer:

    Using parentheses with continue causes a syntax error -> Option C
  4. Quick Check:

    continue has no parentheses in Go [OK]
Hint: Don't add parentheses after continue [OK]
Common Mistakes:
  • Writing continue() instead of continue
  • Confusing continue with break
  • Misreading loop condition as error
5. You want to print all numbers from 1 to 10 except multiples of 3 using a for loop and continue. Which code snippet correctly achieves this?
hard
A. for i := 1; i <= 10; i++ { if i % 3 != 0 { continue } fmt.Println(i) }
B. for i := 1; i <= 10; i++ { if i % 3 == 0 { continue } fmt.Println(i) }
C. for i := 1; i <= 10; i++ { if i % 3 == 0 { break } fmt.Println(i) }
D. for i := 1; i <= 10; i++ { if i % 3 == 0 { fmt.Println(i) continue } }

Solution

  1. Step 1: Understand the goal

    We want to skip printing numbers divisible by 3 and print all others from 1 to 10.
  2. Step 2: Analyze each option

    for i := 1; i <= 10; i++ { if i % 3 == 0 { continue } fmt.Println(i) } skips printing multiples of 3 using continue correctly. for i := 1; i <= 10; i++ { if i % 3 != 0 { continue } fmt.Println(i) } skips non-multiples, printing only multiples. for i := 1; i <= 10; i++ { if i % 3 == 0 { break } fmt.Println(i) } breaks the loop early. for i := 1; i <= 10; i++ { if i % 3 == 0 { fmt.Println(i) continue } } prints multiples and skips others incorrectly.
  3. Final Answer:

    for i := 1; i <= 10; i++ { if i % 3 == 0 { continue } fmt.Println(i) } -> Option B
  4. Quick Check:

    continue skips multiples of 3, print others [OK]
Hint: Use if condition with continue to skip unwanted values [OK]
Common Mistakes:
  • Using break instead of continue
  • Reversing the condition logic
  • Printing inside the continue block
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard