Module 3 · Expressions, operators, and text
Comparing values
Produce boolean results with equality and ordered comparisons.
What you will learn
- Use equality and inequality operators
- Compare numeric ranges without confusing assignment
- comparison
- An expression that evaluates to true or false.
- operand
- A value on one side of an operator.
Loading saved progress…
Understand
Read the idea and follow a worked example.
Why this matters
Coin Quest must ask whether a goal was reached, whether two item names match, or whether time remains before deciding what happens.
The mental model
A comparison asks a question and produces a boolean. == asks whether values are equal; ~= asks whether they differ.
The ordered operators <, >, <=, and >= compare numbers. A single = assigns and is not an equality question.
New words and symbols
--!strict asks Studio to check your code for type mistakes. It is an instruction for the editor and produces no Output message.
print(...) calls the built-in print function. Put the values to show inside its parentheses; separate multiple values with commas. Read the result in Studio's Output panel.
local is read as “local”: it creates a name that is available only in the current code scope.
= is read as “is assigned”: it evaluates the right side and stores that value in the name on the left.
A tiny example
--!strictlocal coins = 8local target = 10local reachedTarget = coins >= targetlocal needsMore = coins < targetprint(reachedTarget, needsMore)Line by line
- 3
coins is the current amount.
- 4
target is the required amount.
- 5
>= includes values equal to or greater than the target.
- 6
< checks whether the current amount is lower.
- 8
The two boolean results are printed.
Read the code aloud
Read one statement at a time: name the value being read, what the operation does, and where its result goes. Keep identifiers exactly as written so you can find them again in the code.
Pause at calls, conditions, and loops. Explain when the body runs before moving to the next statement; use the line notes above when a symbol is unfamiliar.
Execution trace
Begin at the first executable statement. Comments and blank lines do not run; a branch chooses which block runs, and a loop may revisit its body.
Line 3: coins is the current amount.
Line 4: target is the required amount.
Line 5: >= includes values equal to or greater than the target.
Line 6: < checks whether the current amount is lower.
Line 8: The two boolean results are printed.
State before and after
Before running, identify the starting values and any existing Studio objects this example needs. List what you expect to change.
After your practice change, check this result: Each comparison produces the boolean you predicted at the boundary value.
Reading or printing a value leaves it unchanged. Look for assignments, calls that change state, and property updates to explain each change you observe.
Predict before running
Which result is true when coins is 8 and target is 10?
Try it
Mark each step after you have tried it.
Common mistake
local reachedTarget = coins = targetA single equals sign is assignment syntax, not an equality comparison. Use == to ask whether two values are equal.
Checkpoint
Submit once you have considered every question. Retries are unlimited.
Recap
- Comparisons produce booleans.
- == compares while = assigns.
- Inclusive operators include the boundary value.
Next: Next, you will combine boolean ideas with and, or, and not.
Studio Companion
Not connected
Connect once. Compatible challenges will prepare automatically as you reach them.