Challenge - 5 Problems
Continue Statement Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2: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; }
Attempts:
2 left
๐ก Hint
Remember that continue skips the rest of the loop body for the current iteration.
โ Incorrect
When i equals 3, the continue statement skips the printf call, so 3 is not printed.
๐ง Conceptual
intermediate2: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; }
Attempts:
2 left
๐ก Hint
Count how many times the inner loop skips printing when j == 1.
โ Incorrect
For each i, j runs 0 to 2. When j == 1, continue skips count++. So count++ runs for j=0 and j=2, two times per i. With i from 0 to 2 (3 times), total is 3*2=6.
๐ง Debug
advanced2: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; }
Attempts:
2 left
๐ก Hint
Check how i is incremented and when continue is called.
โ Incorrect
i is incremented before continue, so loop progresses normally. When i == 3, continue skips printf, so 3 is not printed. Output is 1 2 4 5.
๐ Syntax
advanced2:00remaining
Which option causes a syntax error?
Which of the following code snippets will cause a syntax error due to incorrect use of continue?
Attempts:
2 left
๐ก Hint
Remember continue can only be used inside loops.
โ Incorrect
Option D uses continue inside an if statement that is not inside any loop, causing a syntax error.
๐ Application
expert2: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; }
Attempts:
2 left
๐ก Hint
Add numbers from 1 to 10 but skip those divisible by 4.
โ Incorrect
Numbers 4 and 8 are skipped. Sum of 1 to 10 is 55. Subtract 4 and 8 gives 55 - 12 = 43.