Introduction
Conditions let a program choose different actions depending on what is true right now. If the password matches, open the app; else show an error. If the score is high enough, unlock a badge; else encourage another try. Without conditions, software would follow one rigid path forever.
You already practiced Boolean tests in Logic in Coding. This lesson turns those tests into branching structures: IF, ELSE, and ELSE IF. You will also see conditions guarding loops and living inside functions. Decision skills transfer to block coding diamonds and to your mini project. Keep keyboard accuracy warm on practice.
Learning Objectives
By the end of this lesson, you will be able to:
- Define conditional branching
- Write IF / ELSE / ELSE IF pseudocode
- Nest simple decisions carefully
- Trace which path runs for given inputs
- Design fair, readable rules for beginner apps
Main Lesson
The basic IF
```text
IF score >= 10 THEN
PRINT "Level complete"
END IF
```
When the condition is true, the body runs. When false, the body is skipped. The rest of the program continues afterward.
IF / ELSE: two clear paths
```text
IF passwordCorrect THEN
OPEN dashboard
ELSE
SHOW "Try again"
END IF
```
Exactly one path runs. Else is the “otherwise” safety net—critical for user feedback.
ELSE IF chains: multiple categories
```text
IF percent >= 90 THEN
grade ← "A"
ELSE IF percent >= 80 THEN
grade ← "B"
ELSE IF percent >= 70 THEN
grade ← "C"
ELSE
grade ← "Needs practice"
END IF
```
Order matters. Put the most specific or highest thresholds first so earlier matches do not block later ones incorrectly.
| Percent | Path taken (with above chain) |
|---|---|
| 95 | A |
| 82 | B |
| 70 | C |
| 40 | Needs practice |
Conditions use logic expressions
Any Boolean expression can drive a branch:
- Simple:
lives == 0 - Compound:
hasTicket AND age >= 12 - Negated:
NOT isPaused
Review operators anytime in Logic in Coding.
Nesting (use sparingly)
```text
IF loggedIn THEN
IF isAdmin THEN
SHOW adminMenu
ELSE
SHOW userMenu
END IF
ELSE
SHOW loginPrompt
END IF
```
Nesting is powerful but can become a maze. Prefer clearer chains or functions like showMenuFor(role) when readability suffers.
Conditions + loops + functions
Patterns you will reuse:
- Loop guarded by condition — while attempts remain and not success
- Condition inside loop — if item matches, count it
- Function returns Boolean —
IF isValid(email) THEN submit
These combinations create real program intelligence.
Designing user-friendly decisions
Good product conditions:
- Always provide feedback on the else path when users expect it
- Avoid silent failures (“nothing happened”)
- State thresholds explicitly (
>= 70, not vibes) - Handle edge values intentionally (exactly 70 should map somewhere)
| Silent / harsh rule | Friendlier rule |
|---|---|
| Wrong password → do nothing | Show error and remaining attempts |
| Score 69 → crash | Show “Close—try again” message |
| Empty name accepted | Else ask for a name before continuing |
Real apps and conditions
Login walls, age gates, discount checks, game collisions, permission prompts, and grading tools are condition engines. Typing platforms decide pass/fail highlights per character using comparison conditions—tools like TYPE10X Practice depend on rapid correct/incorrect branching for each key.
Key Definitions
- Condition / conditional statement — A structure that runs code only when a test is true (and optionally handles false paths).
- Branching / control flow — Choosing different instruction paths.
- IF — Run a block when a condition is true.
- ELSE — Run an alternate block when the IF condition is false.
- ELSE IF / ELIF — Check another condition when previous ones failed.
- Nested condition — A condition inside another condition’s body.
- Boolean expression — The true/false test used by the condition.
- Edge case — Boundary input that needs explicit handling.
- Default path — The final ELSE when no earlier condition matched.
- Guard clause (intro) — An early IF that exits or returns when a requirement fails.
Examples
Example 1: Traffic light robot
If sensor sees red, stop; else if yellow, slow; else go.
Example 2: Cart checkout
If cart empty, disable pay button; else enable and show total.
Example 3: Health pickup
If health < maxHealth, add 1; else ignore pickup.
Example 4: Attendance
If arrival <= start, mark present; else if hasExcuse, mark excused; else mark late.
Real-World Scenarios
Scenario A — Debate over grade borders
Students argue whether 90 should be A or B. Writing the ELSE IF chain and testing boundary values ends the debate with evidence.
Scenario B — Inclusive game design
A “you lose” branch without hints frustrates beginners. Adding else messages and a practice mode flag improves learning.
Scenario C — Security basics
An app that opens admin tools whenever isAdmin OR true by mistake is a logic bug with real risk—conditions must match intended policy.
Tips
Warnings
Did You Know
Common Mistakes
- Forgetting an ELSE when users need feedback
- Using assignment (
=) instead of comparison where languages distinguish them - Ordering ELSE IF ranges incorrectly
- Testing the wrong variable
- Writing conditions that can never be true together without noticing
Interactive Exercise
Branch Tracer (15 minutes)
Given:
```text
IF temp >= 30 THEN
message ← "Hot"
ELSE IF temp >= 20 THEN
message ← "Warm"
ELSE IF temp >= 10 THEN
message ← "Cool"
ELSE
message ← "Cold"
END IF
```
Predict message for: 35, 20, 10, 9, 20.0 (same as 20), and −5. Then rewrite the chain if your teacher wants Fahrenheit thresholds instead.
Practice Questions
- What does an ELSE block do?
- Why does order matter in ELSE IF chains?
- How do Boolean operators support conditions?
- What is an edge case in grading thresholds?
- Give a classroom rule as an IF/ELSE plan.
Mini Challenge
Design conditions for a “study streak” screen:
- If days >= 7 AND accuracy >= 90 → “Legend streak”
- Else if days >= 3 → “Building habit”
- Else → “Start today—even 5 minutes on practice helps”
Write pseudocode and present with three example user profiles.
Summary
Conditions convert Boolean logic into real program choices through IF, ELSE, and ELSE IF. Clear order, edge-case testing, and helpful else paths make software feel smart and fair. Combined with variables, loops, and functions, conditions complete the core control toolkit for beginners. Next you will apply these ideas visually in block coding.
Student Checklist
- [ ] I can write IF / ELSE / ELSE IF plans
- [ ] I understand why branch order matters
- [ ] I can trace paths with sample inputs
- [ ] I can combine logic expressions into conditions
- [ ] I completed Branch Tracer and the mini challenge
Teacher Notes
- Act out branches with doorways labeled IF/ELSE in the classroom.
- Use paper flowcharts before pseudocode for visual learners.
- Provide broken ELSE IF chains with unreachable grades to debug.
- Require edge-case test tables in assignment rubrics.
- Link to digital citizenship: permission checks are ethical condition designs.
FAQ
Q: Can I use many ELSE IFs?
Yes, but if you have huge category lists, data structures or tables may be cleaner later.
Q: What if two conditions could both be true?
In a chain, the first true one wins—design intentionally.
Q: Are switch/case statements conditions too?
They are related branching tools in some languages; IF/ELSE is the universal beginner model.
Q: Do block editors show conditions?
Yes—often as diamond or if-then block shapes with Boolean plugs.
Q: What should I learn next?
Continue to Block Coding to snap these ideas into visual scripts.
Related Lessons
Related Blog Posts
- Explore more digital learning tips on the TYPE10X Blog
- Build keyboard confidence with Free Typing Practice
Next Lesson CTA
You can now branch programs with intentional IF/ELSE decisions. Next, put logic into visual scripts—continue to Block Coding.