0
0
C++programming~10 mins

Continue statement in C++ - Interactive Code Practice

Choose your learning style9 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.