0
0
Cprogramming~20 mins

Continue statement - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Continue Statement Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
Output of loop with continue
What is the output of this C program?
C
#include <stdio.h>

int main() {
    for (int i = 1; i <= 5; i++) {
        if (i == 3) {
            continue;
        }
        printf("%d ", i);
    }
    return 0;
}
A1 2 4 5
B2 3 4 5
C1 2 3 4 5
D1 2 3 4
Attempts:
2 left
๐Ÿ’ก Hint
Remember that continue skips the rest of the loop body for the current iteration.
๐Ÿง  Conceptual
intermediate
2:00remaining
Effect of continue in nested loops
In the following nested loops, how many times will the inner printf execute?
C
#include <stdio.h>

int main() {
    int count = 0;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (j == 1) {
                continue;
            }
            count++;
        }
    }
    printf("%d", count);
    return 0;
}
A0
B6
C3
D9
Attempts:
2 left
๐Ÿ’ก Hint
Count how many times the inner loop skips printing when j == 1.
๐Ÿ”ง Debug
advanced
2:00remaining
Identify the error caused by continue
What error will this code produce when compiled or run?
C
#include <stdio.h>

int main() {
    int i = 0;
    while (i < 5) {
        i++;
        if (i == 3) {
            continue;
        }
        printf("%d ", i);
    }
    return 0;
}
APrints: 1 2 4 5
BCompilation error
CInfinite loop
DPrints: 1 2 3 4 5
Attempts:
2 left
๐Ÿ’ก Hint
Check how i is incremented and when continue is called.
๐Ÿ“ Syntax
advanced
2:00remaining
Which option causes a syntax error?
Which of the following code snippets will cause a syntax error due to incorrect use of continue?
Ado { if (0) continue; } while(0);
Bfor (int i = 0; i < 5; i++) { if (i == 2) continue; printf("%d", i); }
Cwhile (0) { continue; }
Dif (1) { continue; }
Attempts:
2 left
๐Ÿ’ก Hint
Remember continue can only be used inside loops.
๐Ÿš€ Application
expert
2:00remaining
Count numbers skipping multiples of 4
What is the output of this program that uses continue to skip multiples of 4?
C
#include <stdio.h>

int main() {
    int sum = 0;
    for (int i = 1; i <= 10; i++) {
        if (i % 4 == 0) {
            continue;
        }
        sum += i;
    }
    printf("%d", sum);
    return 0;
}
A40
B50
C43
D55
Attempts:
2 left
๐Ÿ’ก Hint
Add numbers from 1 to 10 but skip those divisible by 4.