Introduction
Logic in coding is how programs decide what is true or false so they can choose the right path. Unlock doors only when the password is correct. Award a badge only when score is high and accuracy is strong. Hide a hint when the player already succeeded. Those rules are Boolean logic wearing product clothing.
This lesson sits between variables and conditions. You will practice comparisons and combine them with AND, OR, and NOT. The same ideas power loops stop rules and later functions. Clear typing helps when you enter operators—stay sharp on practice.
Learning Objectives
By the end of this lesson, you will be able to:
- Define Boolean values and expressions
- Compare numbers and text with common operators
- Build compound conditions with AND, OR, NOT
- Interpret a beginner truth table
- Translate classroom rules into logical expressions
Main Lesson
True, false, and questions programs ask
A Boolean value is either true or false. Programs constantly ask yes/no questions:
- Is
score >= 10? - Is
usernameempty? - Is
soundOntrue?
The answer is not “maybe.” For a given moment and given values, the expression evaluates to true or false.
Comparison operators
| Operator (common) | Meaning | Example (true when…) |
|---|---|---|
== or equals | Equal to | score == 10 |
!= | Not equal to | role != "guest" |
> | Greater than | wpm > 40 |
< | Less than | errors < 3 |
>= | Greater or equal | age >= 13 |
<= | Less or equal | battery <= 15 |
Languages differ slightly in spelling, but the ideas match. In algorithms and pseudocode you can write “IF score is at least 10.”
AND, OR, NOT
Compound logic combines smaller checks:
| Operator | Everyday meaning | Coding idea |
|---|---|---|
| AND | Both must be true | Enter only if password correct AND account active |
| OR | At least one true | Discount if student OR teacher |
| NOT | Flip true↔false | If NOT loggedIn, show login page |
Examples:
score >= 80 AND accuracy >= 95— strict excellence ruleisAdmin OR isTeacher— either role can open the toolsNOT isPaused— game runs only when not paused
Beginner truth tables
For two inputs A and B:
| A | B | A AND B | A OR B |
|---|---|---|---|
| false | false | false | false |
| false | true | false | true |
| true | false | false | true |
| true | true | true | true |
NOT table:
| A | NOT A |
|---|---|
| true | false |
| false | true |
Truth tables look formal, but they prevent arguments about what a rule “should” mean. Coders prefer tables over vague vibes.
Parentheses and clarity
Complex rules need grouping:
(score >= 50 AND hasBonus) OR isChampionscore >= 50 AND (hasBonus OR isChampion)
Those two are different. Write parentheses when combining AND with OR so future-you (and teammates) know the intended grouping—just like order mattered in algorithms.
Logic in products you use
| Product rule | Logic idea |
|---|---|
| Submit button enabled only when all required fields filled | AND across field checks |
| “Remember me” on login screens | Store Boolean preference |
| Night mode after sunset or when user toggles it | OR between automatic and manual |
| Typing test success when WPM and accuracy thresholds met | AND of two comparisons |
Sites like TYPE10X Practice use measurements and thresholds—classic logic under the hood.
From logic to control flow
Logic expressions do little alone until a program acts on them:
- Conditions use IF/ELSE paths
- Loops repeat while a condition stays true
- Filters keep only items where a test is true
This lesson builds the brain; next lessons attach the steering wheel.
Key Definitions
- Boolean — A true/false value.
- Expression — A combination of values and operators that produces a result.
- Comparison operator — Symbol/word that compares two values.
- Logical operator — AND, OR, NOT (and similar) combining or flipping Booleans.
- Compound condition — Multiple checks joined together.
- Truth table — A chart of outputs for all input combinations.
- Predicate (intro) — A fancy word for a true/false test.
- Short-circuit (intro) — Some languages stop evaluating early when the result is already known.
- Edge case — A tricky boundary situation (exactly 0, empty text, exactly the threshold).
- Control flow — The order paths a program takes based on logic.
Examples
Example 1: Door lock
Unlock if pinCorrect == true AND attempts < 5.
Example 2: Free shipping
total >= 50 OR hasMembership == true.
Example 3: Show hint
Show hint if NOT foundTreasure AND timeLeft < 30.
Example 4: Club eligibility
Join coding club if grade >= 6 AND (hasLaptop OR usesSchoolLab).
Real-World Scenarios
Scenario A — Fairness debate
Players argue about badge rules. Writing the rule as a Boolean expression plus a truth table ends the argument with clarity.
Scenario B — Attendance app
Mark late if arrivalTime > startTime AND hasExcuse == false. Logic prevents incorrect “late” labels when excuses exist.
Scenario C — Safety filter
A chat tool blocks messages when banned words are found OR links look suspicious. Compound OR logic expands protection.
Tips
>= 10 or > 10 the real requirement?Warnings
"Admin" vs "admin"). Decide rules explicitly.Did You Know
Common Mistakes
- Using OR when everyday speech meant AND (or the reverse)
- Forgetting NOT flips the entire condition you intended
- Comparing the wrong variables
- Ignoring equals-at-boundary cases
- Writing ultra-long expressions no human can read—split them
Interactive Exercise
Rule Translator (15 minutes)
Convert these school rules into Boolean expressions using variable names you invent:
- Enter the lab if you have an ID and a signed waiver.
- Get a spare pencil if you forgot one or your tip broke.
- Unlock extra time if you are not finished and minutes remain.
- Award honor roll if average is at least 90 and absences are under 3.
Then pick one rule and complete a four-row truth table for its two main parts.
Practice Questions
- What is a Boolean value?
- When is A AND B true?
- When is A OR B true?
- Why do parentheses matter in compound logic?
- Give a real app rule that needs NOT.
Mini Challenge
Design the unlock logic for a “study streak” feature: streak badge unlocks only if the user practiced at least 5 days this week AND average accuracy is at least 90 OR a teacher override flag is true. Write the expression with parentheses and explain it in one sentence. Link practice habits to tools like TYPE10X Practice if you wish.
Summary
Coding logic evaluates true/false questions using comparisons and AND/OR/NOT. Truth tables and parentheses keep rules honest. Variables supply the values; logic judges them; conditions and loops act on the judgment. Master this thinking and your programs stop feeling random—they start feeling fair and intentional.
Student Checklist
- [ ] I can explain Boolean true/false
- [ ] I can use comparison operators in examples
- [ ] I understand AND, OR, and NOT
- [ ] I can read a simple truth table
- [ ] I completed Rule Translator and the mini challenge
Teacher Notes
- Act out AND/OR with student volunteers standing/sitting as true/false.
- Use colored cards for true/false voting on sample expressions.
- Collect ambiguous English rules and sharpen them as a class.
- Preview IF statements by executing logic with paper branches.
- Connect to digital citizenship: filters and permissions are logic systems.
FAQ
Q: Is = the same as ==?
In many text languages, = assigns and == compares. Mixing them is a classic bug. In pseudocode, say “set” vs “equals” clearly.
Q: Can more than two conditions be combined?
Yes—chain carefully with parentheses for readability.
Q: Do block-coding tools include logic blocks?
Yes. Look for green or hexagonal Boolean blocks in many block coding editors.
Q: What if both AND paths feel true in real life but code says false?
Check your operators, variable values, and thresholds—trace with actual numbers.
Q: What should I study next?
Continue to Loops to repeat actions while logic stays true—or jump ahead to Conditions after loops as scheduled in this track.
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 evaluate true/false rules with confidence. Next, learn how programs repeat work efficiently—continue to Loops.