C Control Statements

Beginner
14 min read
Updated: Nov 2026
5 examples
8 statement guides

Definition and Usage

Control statements decide which code runs and when. Without them, a C program would only execute top to bottom in a straight line. Decisions (if / switch) pick a branch; jumps (break / continue / goto) steer loops or transfer to a label.

What beginners learn first

Start with if and if-else for true/false choices. Add else-if for grade bands and ranges, then nested if for layered checks. Use switch for menus. Learn break and continue together with C loops. Treat goto as advanced.

Hub vs single-statement pages

This page teaches how control flow fits a C tutorial: when to choose if vs switch, how else binds, and how jumps work with loops. Each name in the table links to a focused guide with syntax, examples, and FAQs (8 tutorials).

Use braces early.

Always wrap bodies in { }. else binds to the nearest if—braces keep nesting unambiguous and prevent dangling-else bugs.

== vs =

Write if (n == 0) to compare. A single = assigns and is a common beginner bug inside conditions.

switch needs break.

After most case labels, put break; or execution falls into the next case. Fall-through is intentional only when you document it.

C Syntax

The main control forms you will use in beginner C programs:

C
/* if — run when condition is true */
if (condition) {
    /* body */
}

/* if-else — two branches */
if (condition) {
} else {
}

/* else-if ladder — mutually exclusive outcomes */
if (a) {
} else if (b) {
} else {
}

/* switch — compare one value to constants */
switch (value) {
    case 1: /* ... */ break;
    default: break;
}

/* jump inside loops */
break;      /* leave loop or switch */
continue;   /* skip to next iteration */

Compile

C
gcc main.c -std=c11 -o main

Core C Concepts

How to choose a control form in everyday C tutorial work:

StatementWhen to useTypical pattern
ifSingle condition, optional actionif (x > 0) { ... }
if-elseExactly two outcomesif (even) ... else ...
else-ifRanges, grade bands, sign checksif (s>=90) ... else if (s>=80) ...
nested ifLayered requirements (A then B)if (a) { if (b) { ... } }
switchMenu options, day numbers, char codesswitch (c) { case 1: break; }
breakExit loop; end switch caseif (found) break;
continueSkip unwanted loop valuesif (n<0) continue;
gotoRare cleanup / error exitsgoto cleanup;

if vs switch

PreferWhen
else-ifRanges (>= 80), floating comparisons, unrelated conditions
switchOne integer/char value vs many named constants

Learning order in this C tutorial

StageFocus
1. Decisionsif, if-else, else-if
2. Nestingnested if with braces
3. Menusswitch + break + default
4. Loopsbreak / continue with for / while
5. Advancedgoto only after the rest feels natural

How to Use Control Statements in C

A practical workflow for this tutorial track:

  1. Decide whether you have two outcomes, many exclusive paths, or one value vs constants.
  2. Pick if-else, else-if, or switch to match that shape.
  3. Write the condition with ==, <, >=—never a lone =.
  4. Wrap every body in braces; keep else attached to the intended if.
  5. In loops, use continue to skip and break to stop early.
  6. Open a single-statement page from the table when you need a full walkthrough.

Live Preview

Enter a score—the preview runs the same else-if grade ladder used in beginner C tutorials.

Simulates if (score >= 90) … else if (score >= 80) …. Range is 0–100.

Preview
Grade: B

Matched branch: else if (score >= 80)

C Examples

Five starter patterns from a C tutorial. Compile with gcc file.c -std=c11 -o out.

Example 1 — Simple if check

Print a message only when age meets the minimum.

C
#include <stdio.h>

int main(void) {
    int age = 20;

    if (age >= 18) {
        printf("You are eligible to vote.\n");
    }

    return 0;
}
if Tutorial

How It Works

  1. Condition tests age >= 18.
  2. True runs the braced body.
  3. False skips the body with no output.
  4. if alone is for optional actions—no else required.

Example 2 — if-else for even or odd

Two exclusive branches based on remainder.

C
#include <stdio.h>

int main(void) {
    int n = 7;

    if (n % 2 == 0) {
        printf("%d is even\n", n);
    } else {
        printf("%d is odd\n", n);
    }

    return 0;
}
if-else Tutorial

How It Works

  1. % 2 == 0 tests divisibility by 2.
  2. Exactly one branch runs.
  3. Use == for comparison, not =.
  4. if-else covers both true and false outcomes.

Example 3 — else-if grade ladder

Map a score to a letter grade; only the first match runs.

C
#include <stdio.h>

int main(void) {
    int score = 85;

    if (score >= 90) {
        printf("Grade: A\n");
    } else if (score >= 80) {
        printf("Grade: B\n");
    } else if (score >= 70) {
        printf("Grade: C\n");
    } else if (score >= 60) {
        printf("Grade: D\n");
    } else {
        printf("Grade: F\n");
    }

    return 0;
}
else-if Tutorial

How It Works

  1. Order matters—test >= 90 before >= 80.
  2. First match wins; later branches are skipped.
  3. Score 85 lands on B.
  4. Final else catches everything else (F).

Example 4 — switch menu

Route integer choices to actions with case and break.

C
#include <stdio.h>

int main(void) {
    int choice = 2;

    switch (choice) {
        case 1:
            printf("New file\n");
            break;
        case 2:
            printf("Open file\n");
            break;
        case 3:
            printf("Save file\n");
            break;
        default:
            printf("Unknown option %d\n", choice);
    }

    return 0;
}
switch Tutorial

How It Works

  1. switch compares choice to each case.
  2. break stops fall-through into the next case.
  3. default handles invalid menu input.
  4. Best for discrete constants—not score ranges.

Example 5 — break and continue in a loop

Skip non-positive values; stop when sum exceeds a limit.

C
#include <stdio.h>

int main(void) {
    int values[] = {5, -2, 10, 3, 20, 8};
    int n = 6;
    int sum = 0;

    for (int i = 0; i < n; i++) {
        if (values[i] <= 0) {
            continue;
        }
        sum += values[i];
        if (sum > 25) {
            break;
        }
    }

    printf("Stopped at sum: %d\n", sum);

    return 0;
}
break Tutorial

How It Works

  1. continue skips -2.
  2. Adds 5, 10, 3, then 20 → sum 28.
  3. break leaves the loop once sum exceeds 25.
  4. Control + loops appear together constantly in C tutorials.

C Control Statements Table

Statement guides in this C tutorial track. Open any row for a full guide with syntax, examples, and FAQs (8 tutorials).

Conditional branching

4 tutorials

Test conditions and pick one path with if, else, and nested logic.

StatementDescriptionTutorial
if statementRun code when a condition is true.Try it
if-else statementTwo-way branch: true or false.Try it
else-if statementMulti-way ladder; first match wins.Try it
nested ifif inside if for layered checks.Try it

Multi-way selection

1 tutorial

Compare one value against many labeled cases.

StatementDescriptionTutorial
switch statementcase, break, default dispatch.Try it

Jump statements

3 tutorials

Alter loop flow or transfer control to a label.

StatementDescriptionTutorial
break statementExit loop or switch immediately.Try it
continue statementSkip to next loop iteration.Try it
goto statementUnconditional jump to a label.Try it

Edge Cases & Pitfalls

Most control-flow bugs in C tutorials are assignment in conditions, missing braces, or switch fall-through.

=

Assignment inside if

if (n = 0) assigns zero (always false). Use == to compare.

{ }

Dangling else

Without braces, else binds to the nearest if. Always brace nested branches.

case

Missing break in switch

Execution falls into the next case. Add break; unless fall-through is intentional.

ord

else-if order wrong

Test tighter ranges first (>= 90 before >= 80) or every high score becomes the lower grade.

brk

break only exits one level

In nested loops, break leaves only the innermost loop. Plan flags or restructure for multi-level exits.

goto

Spaghetti jumps

Prefer structured if, loops, and functions. Reserve goto for rare cleanup patterns.

Platform Support

if, switch, break, continue, and goto are core C language features—available everywhere C compiles.

FeatureSupportNotes
if / else / else ifUniversalSame on GCC, Clang, MSVC
switch / case / defaultUniversalIntegral / enum types; no floating cases
break / continueUniversalInnermost loop / switch only
goto / labelsUniversalSame function only; use sparingly

Key Takeaways

  • Start with if / if-else, then else-if and nested if.
  • switch for menus; else-if for ranges.
  • break / continue steer loops; break also ends switch cases.
  • Next: if, then if-else and switch.

One line: C control statements choose paths—use if chains for decisions, switch for constants, and break/continue with loops, then open each guide for details.

Frequently Asked Questions

Control statements change program flow based on conditions or jumps. They include if, if-else, else-if, nested if, switch, break, continue, and goto. Together they let programs make decisions and steer loops.
Start with if and if-else for true/false decisions. Add else-if for multiple exclusive outcomes, then nested if for layered checks. Learn switch for menu-style choices, and break/continue once you use loops.
Use switch when comparing one integer or char expression to many constant values (1, 2, 3 or 'A', 'B'). Use else-if for ranges (score >= 80) or unrelated conditions.
break exits the nearest loop or switch entirely. continue skips the rest of the current loop iteration and starts the next one. break is also required after most switch cases to avoid fall-through.
Rarely. Prefer structured if, loops, break, and functions. goto can help in tightly controlled cleanup patterns, but beginners should master if and switch first.
Read the comparison table and examples on this page, then open the if statement tutorial and follow the sidebar order through goto. Pair this track with the C loops tutorials for break and continue practice.

Start with the if statement

Open the basic decision guide first, then continue through if-else, else-if, and switch.

if statement tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful