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.
Fundamentals
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.
Foundation
📝 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 outcomes — if-else
Three or more exclusive paths — else-if or switch
Layered requirements — nested if
Many constants on one variable — switch
Stop a loop or skip one pass — break or continue
Compile
C
gcc main.c -std=c11 -o main
Cheat Sheet
⚡ Quick Reference
Statement
When to use
Typical pattern
if
Single condition, optional action
if (x > 0) { ... }
if-else
Exactly two outcomes
if (even) ... else ...
else-if
Ranges, grade bands, sign checks
if (s>=90) ... else if (s>=80) ...
switch
Menu options, day numbers, char codes
switch (c) { case 1: break; }
break
Exit loop; end switch case
if (found) break;
continue
Skip unwanted loop values
if (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.
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;
}
📤 Output:
You are eligible to vote.
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;
}
📤 Output:
7 is odd
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;
}
📤 Output:
Grade: B
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;
}
📤 Output:
Open file
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;
}
📤 Output:
Stopped at sum: 28
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.
Applications
🚀 Common Use Cases
Validation — if checks age, password, range.
Menus — switch on user choice 1–N.
Classification — else-if for grades, tiers, signs.
Search — loop with break when item found.
Filtering — continue 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.
Important
📝 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.
Pro Tips
🚀 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.
Wrap Up
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.
Your map to every statement tutorial on this site.
5
Core concepts
📝01
if family
Decisions.
Core
🔌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.