Beginner
minutes
Control Flow Terminology
Overview of control flow concepts and terminology in this chapter.
Last updated:
This reference provides an overview of control flow terminology you'll encounter in this chapter. Use it as a quick lookup guide.
Conditional Statements
| Term | Definition | Example |
|---|---|---|
| if statement | Executes code block if condition is true | if (x > 0) { } |
| else statement | Executes if the if condition is false | else { } |
| else if | Chain of conditional checks | else if (x < 0) { } |
| Condition | Boolean expression that controls flow | x > 0, isValid |
| Branch | One path of execution in conditional | The if-block or else-block |
| Dangling else | Ambiguous else matching with nested ifs | Always use braces to avoid |
Switch Statements
| Term | Definition | Example |
|---|---|---|
| switch | Multi-way branch based on value | switch (value) { } |
| case label | Specific value to match against | case 1: |
| default | Handles unmatched values | default: |
| break | Exits the switch statement | break; |
| Fallthrough | Execution continues to next case | Missing break causes this |
| [[fallthrough]] | Attribute indicating intentional fallthrough | [[fallthrough]]; |
Loops
| Term | Definition | Example |
|---|---|---|
| while loop | Repeats while condition is true | while (x > 0) { } |
| do-while loop | Executes at least once, then checks condition | do { } while (x > 0); |
| for loop | Loop with init, condition, and increment | for (int i{0}; i < 10; ++i) |
| Range-based for | Iterates over container elements | for (auto x : container) |
| Infinite loop | Loop that never terminates | while (true) { } |
| Nested loop | Loop inside another loop | Inner loop runs completely each outer iteration |
Loop Components
| Term | Definition | Example |
|---|---|---|
| Loop variable | Variable controlling iteration count | int i in for loop |
| Iteration | One execution of the loop body | Each pass through the loop |
| Loop body | Code executed each iteration | Statements inside { } |
| Loop condition | Expression checked before/after each iteration | i < 10 |
| Increment/Decrement | Changing loop variable each iteration | ++i, i-- |
| Off-by-one error | Loop runs one too many/few times | Using <= instead of < |
Loop Control
| Term | Definition | Example |
|---|---|---|
| break | Immediately exits the loop | break; |
| continue | Skips to next iteration | continue; |
| Early exit | Leaving loop before natural completion | Using break on condition |
| Loop invariant | Condition true at start of each iteration | Used in algorithm proofs |
Conditional Expressions
| Term | Definition | Example |
|---|---|---|
| Ternary operator | Inline conditional expression | x > 0 ? "pos" : "neg" |
| Short-circuit evaluation | Skipping unnecessary condition checks | a && b skips b if a is false |
| Compound condition | Multiple conditions combined | x > 0 && x < 10 |
| Boolean expression | Expression evaluating to true/false | x == y |
Scope in Control Flow
| Term | Definition | Example |
|---|---|---|
| Block scope | Variables limited to { } |
Loop variable in for header |
| Init statement | Declaration in if/switch (C++17) | if (int x{getValue()}; x > 0) |
| Statement scope | Scope of variable declared in statement | Variable in for-init |
Jump Statements
| Term | Definition | Example |
|---|---|---|
| goto | Unconditional jump to label (avoid!) | goto label; |
| Label | Named location for goto | label: |
| return | Exits function, optionally with value | return result; |
Common Patterns
| Term | Definition | Example |
|---|---|---|
| Sentinel value | Special value indicating end | -1 to end input |
| Counter | Variable tracking iterations | int count{0}; |
| Accumulator | Variable collecting results | sum += value; |
| Flag variable | Boolean tracking state | bool found{false}; |
| Guard clause | Early return for edge cases | if (!valid) return; |
Error Handling
| Term | Definition | Example |
|---|---|---|
| Input validation | Checking user input is valid | if (std::cin.fail()) |
| Error state | Stream in failed state | std::cin after bad input |
| Recovery | Restoring from error state | std::cin.clear() |
| Ignore | Discarding unwanted input | std::cin.ignore() |
Create an account to track your progress and access interactive exercises. Already have one? Sign in.
Control Flow Terminology - Quiz
Test your understanding of the lesson.
7 questions
10 minutes
60% to pass
Lesson Discussion
Share your thoughts and questions
💬
No comments yet. Be the first to share your thoughts!