Bird
Raised Fist0
C++programming~10 mins

Continue statement in C++ - 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.

C++
#include <iostream>

int main() {
    for (int i = 1; i <= 5; i++) {
        if (i == 3) {
            [1];
        }
        std::cout << i << " ";
    }
    return 0;
}
Drag options to blanks, or click blank then click option'
Acontinue
Bbreak
Creturn
Dexit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'break' instead of 'continue' which stops the loop completely.
Using 'return' which exits the whole function.
Using 'exit' which ends the program.
2fill in blank
medium

Complete the code to skip all even numbers in the loop.

C++
#include <iostream>

int main() {
    for (int i = 1; i <= 6; i++) {
        if (i % 2 == 0) {
            [1];
        }
        std::cout << i << " ";
    }
    return 0;
}
Drag options to blanks, or click blank then click option'
Aexit
Bcontinue
Creturn
Dbreak
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'break' which stops the loop entirely.
Using 'return' which exits the function.
Using 'exit' which ends the program.
3fill in blank
hard

Fix the error in the code to correctly skip printing negative numbers.

C++
#include <iostream>

int main() {
    int numbers[] = {2, -1, 3, -4, 5};
    for (int i = 0; i < 5; i++) {
        if (numbers[i] < 0) {
            [1];
        }
        std::cout << numbers[i] << " ";
    }
    return 0;
}
Drag options to blanks, or click blank then click option'
Aexit
Bbreak
Creturn
Dcontinue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'break' which stops the loop completely.
Using 'return' which exits the function.
Using 'exit' which ends the program.
4fill in blank
hard

Fill both blanks to skip printing multiples of 3 and continue the loop.

C++
#include <iostream>

int main() {
    for (int i = 1; i <= 10; i++) {
        if (i [1] 3 [2] 0) {
            continue;
        }
        std::cout << i << " ";
    }
    return 0;
}
Drag options to blanks, or click blank then click option'
A%
B==
C!=
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/' instead of '%' for modulus.
Using '!=' instead of '==' in the condition.
Using 'break' instead of 'continue'.
5fill in blank
hard

Fill all three blanks to skip printing numbers less than 5 and continue the loop.

C++
#include <iostream>

int main() {
    int arr[] = {2, 5, 7, 3, 8};
    for (int [1] = 0; [2]; [3]++) {
        if (arr[i] < 5) {
            continue;
        }
        std::cout << arr[i] << " ";
    }
    return 0;
}
Drag options to blanks, or click blank then click option'
Ai
Bi < 5
Dj
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in the loop declaration and condition.
Using 'j' instead of 'i' causing errors.
Incorrect loop condition.

Practice

(1/5)
1. What does the continue statement do inside a loop in C++?
easy
A. It stops the entire loop immediately.
B. It skips the rest of the current loop iteration and moves to the next iteration.
C. It exits the current function.
D. It restarts the program from the beginning.

Solution

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

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

    After skipping, the loop moves to the next iteration immediately without executing the rest of the loop body.
  3. Final Answer:

    It skips the rest of the current loop iteration and moves to the next iteration. -> Option B
  4. Quick Check:

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

Solution

  1. Step 1: Recall the syntax of continue in C++

    The continue statement is a keyword and used alone followed by a semicolon.
  2. Step 2: Check each option's syntax

    Only continue; is valid. The others use parentheses or braces which are incorrect.
  3. Final Answer:

    continue; -> Option A
  4. Quick Check:

    Continue ends with semicolon [OK]
Hint: Continue is a keyword, ends with semicolon [OK]
Common Mistakes:
  • Adding parentheses after continue
  • Using braces or brackets with continue
  • Omitting the semicolon
3. What will be the output of the following C++ code?
for (int i = 1; i <= 5; i++) {
    if (i == 3) continue;
    std::cout << i << " ";
}
medium
A. 1 2 3 4 5
B. 1 2 3 4
C. 1 2 4 5
D. 2 3 4 5

Solution

  1. Step 1: Analyze the loop and condition

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

    Numbers 1 and 2 print normally. At 3, continue skips printing. Then 4 and 5 print.
  3. Final Answer:

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

    Skip 3, print others [OK]
Hint: Continue skips printing 3, others print [OK]
Common Mistakes:
  • Including 3 in output
  • Stopping loop at 3
  • Printing numbers after 3 incorrectly
4. Identify the error in the following C++ code snippet:
for (int i = 0; i < 5; i++) {
    if (i == 2)
        continue
    std::cout << i << " ";
}
medium
A. No error in the code.
B. Incorrect loop condition.
C. Wrong variable type for i.
D. Missing semicolon after continue statement.

Solution

  1. Step 1: Check syntax of continue statement

    The continue statement must end with a semicolon.
  2. Step 2: Identify missing semicolon

    In the code, continue is not followed by a semicolon, causing a syntax error.
  3. Final Answer:

    Missing semicolon after continue statement. -> Option D
  4. Quick Check:

    Continue needs semicolon [OK]
Hint: Always put semicolon after continue [OK]
Common Mistakes:
  • Forgetting semicolon after continue
  • Assuming continue needs parentheses
  • Misreading loop condition as error
5. Consider the following code that sums numbers from 1 to 10 but skips multiples of 3 using continue. What is the final sum?
int sum = 0;
for (int i = 1; i <= 10; i++) {
    if (i % 3 == 0) continue;
    sum += i;
}
std::cout << sum;
hard
A. 52
B. 55
C. 45
D. 50

Solution

  1. Step 1: Identify numbers skipped by continue

    Numbers divisible by 3 (3, 6, 9) are skipped and not added to sum.
  2. Step 2: Calculate sum of numbers 1 to 10 excluding 3, 6, 9

    Sum 1+2+4+5+7+8+10 = 37 + 15 = 52
  3. Final Answer:

    52 -> Option A
  4. Quick Check:

    Sum excluding multiples of 3 = 52 [OK]
Hint: Skip multiples of 3, sum others [OK]
Common Mistakes:
  • Including multiples of 3 in sum
  • Adding all numbers 1 to 10
  • Misunderstanding continue effect
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