C Control Statements

Beginner
⏱️ 14 min read
📚 Updated: Jul 2026
🎯 8 Tutorials
if · switch · break

What You’ll Learn

Control statements decide which code runs and when. Without them, every program would execute top to bottom in a straight line. C gives you if for decisions, switch for menu-style choices, and break/continue to steer loops. This hub explains how they fit together and links to 8 full tutorials—each with five examples and FAQs.

01

if

True/false.

02

else if

Many paths.

03

switch

case labels.

04

break

Exit early.

05

continue

Skip once.

06

8 guides

Full index.

Definition and Usage

A control statement alters the default sequential flow of a C program. Selection statements (if, switch) choose which block runs. Jump statements (break, continue, goto) move execution to another point—most often inside loops or switch cases.

Real programs combine these tools: validate input with if-else, route menu numbers with switch, search an array with a for loop and break when found. This page is your map; each tutorial below goes deep on one statement.

💡
Beginner Tip

Always use braces { } on if and else branches—even for one line. Braces prevent the dangling-else bug and make nested logic easier to read.

📝 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 */

Choosing the right tool

  • Two outcomesif-else
  • Three or more exclusive pathselse-if or switch
  • Layered requirements — nested if
  • Many constants on one variableswitch
  • Stop a loop or skip one passbreak or continue

Compile

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

⚡ Quick Reference

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) ...
switchMenu options, day numbers, char codesswitch (c) { case 1: break; }
breakExit loop; end switch caseif (found) break;
continueSkip unwanted loop valuesif (n<0) continue;

Control Statement Tutorial Index

Search by statement name or browse by category. Every card links to a full guide with five examples and FAQs.

Conditional Branching

4 tutorials

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

Multi-way Selection

1 tutorial

Compare one value against many labeled cases.

Jump Statements

3 tutorials

Alter loop flow or transfer control to a label.

Examples Gallery

Five small programs that combine the most common control statements. Compile with gcc file.c -std=c11 -o out.

📚 Getting Started

Basic if and if-else decisions every beginner writes first.

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;
}

How It Works

age >= 18 is true, so the block runs. If age were 15, the if body would be skipped with no message printed.

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;
}

How It Works

Exactly one branch runs. % 2 == 0 tests divisibility by 2. Use == for comparison, not = (assignment).

📈 Practical Patterns

else-if ladders, switch menus, and loop control.

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;
}

How It Works

Order matters: test >= 90 before >= 80. Score 85 matches B and skips C, D, and 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;
}

How It Works

break after each case prevents fall-through into the next label. default catches invalid menu input.

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;
}

How It Works

-2 triggers continue (skipped). After adding 5, 10, 3, and 20, sum is 28 and break leaves the loop. Control statements and loops work together constantly.

🚀 Common Use Cases

  • Validationif checks age, password, range.
  • Menusswitch on user choice 1–N.
  • Classificationelse-if for grades, tiers, signs.
  • Search — loop with break when item found.
  • Filteringcontinue to skip bad data rows.
  • Games & UI — nested if for state and input.

🧠 How Control Statements Fit Together

1

Evaluate condition

if or switch tests an expression.

Decide
2

Run chosen branch

One path executes; others are skipped.

Execute
3

Loops repeat

break/continue steer iteration inside loops.

Repeat
=

Structured program flow

Decisions + loops + jumps build interactive, correct C programs.

📝 Notes

  • Zero is false in C; any non-zero value is true in conditions.
  • Use == to compare, = to assign—do not mix them in if.
  • switch only accepts integer types—not float or strings.
  • Put break; after switch cases unless fall-through is intentional.
  • continue in while may need an early increment to avoid infinite loops.
  • Pair this hub with C Loops for full repetition coverage.

🚀 Usage Tips

  • Learn in sidebar order — if → if-else → else-if → nested-if → switch → break → continue → goto.
  • Brace every branch — prevents dangling else and future bugs.
  • Prefer else-if over nested if when outcomes are flat and exclusive.
  • Use switch for menus — cleaner than ten else if (x==N) lines.
  • Read each tutorial — every statement page has five examples and six FAQs.

Conclusion

Control statements are how C programs respond to data instead of running blindly line by line. Master if and switch for decisions, then break and continue inside loops for finer control.

Browse the index above or start with the if statement tutorial and follow the sidebar through goto.

💡 Best Practices

✅ Do

  • Use braces on every if and else
  • Order else-if thresholds from high to low
  • Add default in switch for unknown input
  • Use meaningful conditions (age >= 18, not magic numbers alone)
  • Combine with loops from the loops hub

❌ Don’t

  • Write if (x = 5) when you mean ==
  • Omit break in switch by accident
  • Nest if four levels deep without refactoring
  • Use goto for ordinary branching
  • Forget that continue is invalid in switch

Key Takeaways

Knowledge Unlocked

Five things to remember about control statements

Your map to every statement tutorial on this site.

5
Core concepts
🔌 02

switch

Many cases.

Menus
🛑 03

break

Exit.

Loops
🔄 04

continue

Skip once.

Filter
📚 05

8 guides

Full index.

Hub

❓ 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, repeat with loops, and exit or skip iterations.
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. See the goto tutorial for when it appears in real code.
Read the overview and comparison table, try the five examples, then open the if statement tutorial and follow the sidebar order through goto.
Did you know?

C programs combine if chains for decisions, switch for many constants on one value, and break/continue inside loops. else always binds to the nearest if—braces keep nesting unambiguous.

Start Your First Statement Tutorial

Open the if statement guide, then follow the sidebar through switch, break, and continue.

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