Python Conditional Branching: if, else if, else & Guards
Dart executes control flow branching using `if`, `else if`, and `else` statements. Because Dart strictly enforces type safety, conditional test expressions must evaluate strictly to the boolean type `bool`. Combining boolean predicates with logical operators (`&&`, `||`, `!`) allows clean validation guards.
"`if/else` is like a railroad switch track: depending on whether the switch is set to true or false, the train proceeds down track A or track B."
Deep Dive: How It Works
Strict Boolean Requirement: `if (1)` or `if ("str")` will fail compilation; only expressions evaluating to `bool` are valid.
Short-Circuit Evaluation: In `exprA && exprB`, `exprB` is never evaluated if `exprA` is false.
Inline Ternary: `final status = isReady ? "RUN" : "WAIT";` provides concise conditional value assignment.
Syntax Blueprint
if (score >= 90) {
grade = "A";
} else if (score >= 80) {
grade = "B";
} else {
grade = "C";
}Sequential boolean condition evaluation.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Using assignment `=` instead of equality `==` inside an if statement.Why it happens: Typo error. Dart protects you by rejecting non-boolean evaluations at compile time.
How to fix: Always use `==` or `!=` for equality comparisons.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Check Temperature Range
Given `int temp = 32;`.
If `temp > 30`, print `HOT`. Else if `temp >= 15`, print `WARM`. Else print `COLD`.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.