Continue Statement in C Language: Syntax, Examples & Rules (Unit 2)



BCA Sem 1  |  Unit 2  |  Computer Concepts & C Programming

Continue Statement in C Language — BKNMU Junagadh

Jump Statements, Iteration Skipping, Loop Control Behavior, and Differences from Break

BKNMU Junagadh NEP 2020 Unit 2 Continue Statement Jump Control Iteration Skip
In simple words: Welcome to Unit 2! The continue statement in C is a jump statement that skips the remaining statements in the current iteration of a loop (for, while, or do...while) and immediately transfers execution control to the next iteration pass.
📖 Core Features of Continue Statement

The continue keyword alters loop behavior in four distinct ways across different contexts:

Skip Remaining Code

1. Skipping Iterations

Instantly stops execution of statements written below it inside the loop body for that specific run only.

for( ; ; i++)

2. Behavior in For Loop

Jumps directly to the counter update/increment step (i++) before evaluating the condition for the next pass.

while (condition)

3. Behavior in While Loops

Jumps directly to the test condition line at the top (or bottom for do...while) for re-evaluation.

Filtering Data

4. Selective Execution

Ideal for skipping invalid values, unwanted inputs, or filtering specific numbers (like skipping odd/even values).

1️⃣ Master Table: Continue vs. Break Statement

Here is a detailed comparative breakdown showing how continue differs fundamentally from break:

Comparison ParameterBreak Statement (break;)Continue Statement (continue;)
Primary EffectTerminates the entire loop completely.Skips only the remaining part of the current iteration.
Execution FlowJumps out of the loop body to the statement placed after the loop.Jumps to the update step / condition check for the next iteration.
Loop ContinuityLoop stops permanently; no further iterations take place.Loop continues running for subsequent remaining iterations.
Switch Statement UsageValid and strictly required to prevent case fallthrough.Invalid inside switch blocks (unless enclosed inside a loop).
ℹ️ Scope Restriction: Just like break, the continue statement can ONLY be used inside loop bodies (for, while, do...while). Using continue outside a loop will trigger a compile-time error!
💻 Code Examples & Practical Applications

1. Skipping a Specific Value in a For Loop:

#include <stdio.h>

int main() {
    int i;

    for (i = 1; i <= 5; i++) {
        if (i == 3) {
            printf("Skipping iteration at i = 3\n");
            continue; // Skips printf below for i = 3
        }
        printf("Value: %d\n", i);
    }

    return 0;
}

2. Printing Only Even Numbers (1 to 10):

#include <stdio.h>

int main() {
    int i;

    for (i = 1; i <= 10; i++) {
        // Skip odd numbers
        if (i % 2 != 0) {
            continue;
        }
        printf("Even Number: %d\n", i);
    }

    return 0;
}

3. Continue inside a While Loop (Counter Placement Caution):

#include <stdio.h>

int main() {
    int i = 0;

    while (i < 5) {
        i++; // Counter incremented BEFORE continue
        if (i == 3) {
            continue; // Jumps directly to while(i < 5)
        }
        printf("i = %d\n", i);
    }

    return 0;
}
🔄 Step-by-Step Execution Flow
1

Step 1: Trigger Condition Checked

An if statement checks whether current iteration data should be skipped.

2

Step 2: Execute Continue Keyword

When triggered, continue; halts processing for all remaining lines in the current block.

3

Step 3: Jump to Next Pass

Control jumps to the counter update step (in for loops) or condition re-test (in while / do...while loops).

💡 Exam Tip on While Loop Pitfall: In a while loop, if you place your counter increment (i++) after the continue statement, triggering continue will bypass the increment step, freezing your program in an infinite loop! Always update your variable prior to calling continue in while loops.
⚠️ Switch Statement Fallacy: Remember for GTU/BKNMU exam MCQs: continue CANNOT be used directly inside a switch statement to skip cases. It only applies to enclosing loops!
📝 Quick Revision — Key Exam Points
  • Statement Type: Unconditional Jump / Control Keyword.
  • Primary Function: Bypasses remaining statements in the current iteration pass.
  • For Loop Effect: Jumps to increment/decrement counter update expression.
  • While / Do-While Effect: Jumps directly to condition re-evaluation.
  • Invalid Context: Cannot be used directly inside switch blocks without an enclosing loop.

Post a Comment

Thanks for comment.

Previous Post Next Post