Bird
0
0

How can you modify this loop to skip printing the number 4?

hard📝 Application Q9 of 15
C - Loops
How can you modify this loop to skip printing the number 4?
for(int i = 1; i <= 5; i++) {
    printf("%d ", i);
}
AAdd 'if(i == 4) continue;' inside the loop before printf
BChange loop to 'for(int i = 1; i < 4; i++)' only
CUse 'break' when i equals 4
DRemove the printf statement
Step-by-Step Solution
Solution:
  1. Step 1: Understand the goal to skip printing 4

    We want to print 1, 2, 3, 5 but skip 4.
  2. Step 2: Use continue to skip printing 4

    Adding 'if(i == 4) continue;' skips the rest of the loop body for i=4, so printf is not called.
  3. Final Answer:

    Add 'if(i == 4) continue;' inside the loop before printf -> Option A
  4. Quick Check:

    Continue skips current iteration [OK]
Quick Trick: Use continue to skip unwanted iterations [OK]
Common Mistakes:
  • Using break which stops entire loop
  • Changing loop bounds incorrectly
  • Removing print statement entirely

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes