Logic
Your "Decision Maker"
Asking Questions and Making Logical Decisions
What it is
The Logic category contains blocks used to compare values, combine conditions, reverse logical results, test membership or identity, and work with Boolean values.
Most Logic operations produce one of two results:
TRUE or FALSE
These results can then be used by Control blocks to decide what the program should do.
What it does
Logic blocks allow a program to ask questions such as:
- Are two values equal?
- Are two values different?
- Is one value greater than another?
- Is a value between two limits?
- Are two conditions true?
- Is at least one condition true?
- Are the conditions different?
- Is something NOT true?
- Is a value contained in a list?
- Are two objects the same object?
- Which value should be selected according to a condition?
- How should a value be interpreted as TRUE or FALSE?
Example
A sensor might produce a numerical reading.
The program can ask:
Is sensor value > 500?
The comparison produces:
TRUE or FALSE
and Control can use that result:
IF sensor value > 500 → Perform Action
Think of Logic blocks as the questions your program asks before deciding what to do.
Fun Guide to Logic Blocks (Clu-blocks Pro)
What it is: Blocks that allow you to make decisions.
What it does: Answers Yes/No questions to make decisions.
Example: "If the button is pressed → turn on the LED, if not → turn it off."
It's the thinking brain that says "yes" or "no."
Important! Logic blocks help your robot make decisions, compare things, and choose what to do next. They’re like the robot’s brain checking if something is true or false before acting.
Using the actual Clu-Blocks Pro MicroPython generation, the category can be organized into these conceptual families:
COMPARE → RANGE → COMBINE → REVERSE → BOOLEAN → SELECT → MEMBERSHIP / IDENTITY → CONVERT
| Block | What it does | Dropdown options | What the options mean |
|---|---|---|---|
| Compares two values | =, ≠, <, ≤, >, ≥ | - =: equal- ≠: not equal- <: less than- ≤: less than or equal- >: greater than- ≥: greater than or equal | |
| Checks if x is between two values | <, ≤, >, ≥ | You can build double comparisons like “between” or “outside” | |
| Combines two conditions | and, or, NAND, NOR | - and: both must be true- or: at least one is true- NAND: not both- NOR: neither is true | |
| Flips a condition | — | If something is true, not makes it false and vice versa | |
| A true/false value | true, false | Used to test or trigger actions based on conditions | |
| Represents “nothing” or “empty” | — | Used when a value doesn’t exist or hasn’t been set yet | |
| Runs code based on a condition | — | You choose what happens when something is true or false | |
| Checks if a value is in a list | to, is not in | - to: is in the list- is not in: not in the list | |
| Compares two lists | Yes, is not | - Yes: lists are equal- is not: lists are different | |
| Converts a value to true/false | — | Turns numbers, text, or other values into a logical result |
Quick Tips for Students
- Use comparison blocks to check values (like scores, sensor readings, or time).
- Use true/false blocks to control decisions like turning on a light only if it’s dark.
- Use list checks to see if something belongs to a group (like a password or command).
- Use logic combos (
and,or,not) to build smarter conditions.
1. Comparing Two Values
The Comparison block compares two values.
The screenshot originally showed only: 0 = 0
but the real generation confirms six comparison operations.
| Block Option | MicroPython | Question Being Asked |
|---|---|---|
| Equal | == | Are the values equal? |
| Not Equal | != | Are the values different? |
| Less Than | Is the first value smaller? | |
| Less Than or Equal | <= | Is the first value smaller or equal? |
| Greater Than | > | Is the first value larger? |
| Greater Than or Equal | >= | Is the first value larger or equal? |
0 == 0produces a Boolean result.
Easy way to remember
Comparison → Question → TRUE / FALSE
2. Equal vs. Assignment
This distinction is especially important for beginners.
x = 5
means: Store 5 in x.
But:
x == 5
means: Is x equal to 5?These operations have completely different purposes.
=stores a value.==compares values.
This connects the Variables and Logic categories.
3. Chained Comparisons
0 < x < 2The actual Clu-Blocks Pro generation confirms four forms:
0 < x < 2
0 <= x <= 2
0 > x > 2
0 >= x >= 2This allows one value to be compared against two limits in a single logical expression.
Example
0 < x < 100asks whether x satisfies both comparisons.
This is especially useful for range checking.
4. Strict vs. Inclusive Comparisons
Students should understand the difference between:
- < Less than
<=Less than or equal to
Similarly:
>Greater than>=Greater than or equal to
The = portion means that the boundary itself can also satisfy the comparison.
5. Combining Conditions
Sometimes one condition is not enough.
Clu-Blocks Pro can combine Boolean conditions using several operations.
AND
True and TrueAND requires both conditions to be true for the complete expression to be true.
| A | B | A AND B |
|---|---|---|
| TRUE | TRUE | TRUE |
| TRUE | FALSE | FALSE |
| FALSE | TRUE | FALSE |
| FALSE | FALSE | FALSE |
Example
Button Pressed AND Obstacle Detected
Both conditions must be satisfied.
6. OR
False or FalseWith OR, the expression is TRUE when at least one supplied condition is true.
| A | B | A OR B |
|---|---|---|
| TRUE | TRUE | TRUE |
| TRUE | FALSE | TRUE |
| FALSE | TRUE | TRUE |
| FALSE | FALSE | FALSE |
A simple student-friendly interpretation is:
AND asks for both. OR accepts either one or both.
7. XOR
Clu-Blocks Pro also generates the XOR operation:
True ^ TrueFor Boolean values, XOR is TRUE when the two Boolean states are different.
| A | B | A XOR B |
|---|---|---|
| TRUE | TRUE | FALSE |
| TRUE | FALSE | TRUE |
| FALSE | TRUE | TRUE |
| FALSE | FALSE | FALSE |
An easy way to introduce this is:
XOR asks whether the two Boolean states are different.
This is more advanced than AND and OR, so I would introduce XOR later in the course.
8. Inverse XOR
not (True ^ True)I would treat this as an advanced logical operation, rather than introducing it together with basic AND/OR.
9. NOT
The NOT block reverses one Boolean value.
Clu-Blocks Pro generates:
not True
or:
not FalseThe relationship is:
- TRUE → NOT → FALSE
- FALSE → NOT → TRUE
NOT means: use the opposite Boolean result.
10. Boolean Values
True
and:
FalseA Boolean therefore represents one of two logical states:
TRUE or:FALSE
Booleans are fundamental because comparisons and logical questions eventually produce values that Control blocks can use.
11. null Generates None
The interface displays: null
but your actual Clu-Blocks Pro generation confirms that the generated MicroPython value is:
NoneFor beginners, I would explain None simply as:
A special value representing the absence of a normal value.
This can be explored in greater depth later when students begin using Functions and returned values.
12. Choosing Between Two Values
The conditional-value block selects one value or another according to a condition.
value_if_true if condition else value_if_falseThis produces a value, rather than acting like the larger instruction-containing if block from the Control category.
Conditional Value vs. Control if
These two blocks should not be confused.
Control if
- Determines which instructions execute.
Logic Conditional Value
- Determines which value is produced.
An easy distinction is:
- Control
if→ Choose an action - Logic conditional → Choose a value
13. Membership: in
x in [0, 1, 2, 3]This asks whether:x
appears in the supplied collection.
Conceptually:
Value → Is it IN this collection? → TRUE / FALSE
14. Membership: not in
x not in [0, 1, 2, 3]This asks the opposite membership question:
Is x NOT contained in this collection?
The two operations therefore form a natural pair:
| Operation | Question |
|---|---|
| in | Is the value contained in the collection? |
| not in | Is the value absent from the collection? |
15. Identity: is
[0, 1, 2, 3] is [0, 1, 2, 3]The important correction here is that is should not be described simply as another equality test.
In Python, is is an identity operation.
For beginner documentation, the safest distinction is:
==→ Compare valuesis→ Test identity
This is a more advanced concept and does not need to be introduced with basic equality.
16. Identity: is not
Clu-Blocks Pro also generates:
[0, 1, 2, 3] is not [0, 1, 2, 3]This is the opposite identity operation.
The confirmed relationships are:
| Operator | Main Idea |
|---|---|
| in | Membership |
| not in | Negative membership |
| is | Identity |
| is not | Negative identity |
This is a major correction to our original version, where these options could not be identified from the closed selector.
17. Convert to Boolean
The visible example is: to boolean x
and Clu-Blocks Pro generates:
bool(x)This converts the supplied value using Python's Boolean conversion.
Conceptually:
Value → bool() → Boolean Result
Because different data types can behave differently when converted to Boolean, detailed conversion rules can be introduced later when students have learned more about Variables and data types.
Quick Guide for Students
- Are two values equal? Use:
== - Are two values different? Use:
!= - Is one value larger or smaller? Use:
<=,>, or>= - Does a value need to be between two limits? Use a Chained Comparison.
- Must both conditions be true? Use: AND
- Can either condition be true? Use: OR
- Do the two Boolean states need to be different? Use: XOR
- Do I need the opposite of a condition? Use: NOT
- Do I need a fixed logical value? Use: TRUE / FALSE
- Do I need to choose between two resulting values? Use the Conditional Value block.
- Do I need to check whether something is inside a collection? Use: in
- Do I need to check that something is not inside a collection? Use: not in
- Do I need an identity test? Use: is / is not
- Do I need to convert a value to Boolean? Use: to boolean
Quick Reference
| Family | Operations | Main Idea |
|---|---|---|
| Comparison | ==, != | Equal / different. |
| Ordering | , <=, >, >= | Compare numerical ordering or boundaries. |
| Chained Comparison | < x , <= x <=, > x >, >= x >= | Compare a value against two limits. |
| AND | and | Both conditions. |
| OR | or | At least one condition. |
| XOR | ^ | Boolean states differ. |
| Inverse XOR | not (... ^ ...) | Reverse the XOR result. |
| NOT | not | Reverse a Boolean result. |
| Boolean | True, False | Fixed logical values. |
| null | None | Special no-value object. |
| Conditional Value | A if condition else B | Select one of two values. |
| Membership | in, not in | Test whether a value belongs to a collection. |
| Identity | is, is not | Test object identity. |
| Boolean Conversion | bool(x) | Convert a supplied value to Boolean. |
