Calculating with symbols
Plus, minus, greater than, equal. Symbols that do something with values are called operators. Some make a new value, some compare two and give true or false. The "true·false" of last time's condition comes from right here.
Add, subtract, multiply
The most familiar operators
are calculation.
Plus, minus,
times, divide.
Put in two values
and out comes one new value.
Below, change the symbol
and see how the result changes.
Two values, one symbol, one new value. (7 + 4 = 11 · change the symbol, the result changes)
Two numbers
and one symbol is all it takes.
By the symbol
it adds or subtracts.
Making a new value
out of values like this
is an arithmetic operator.
Just like a calculator.
Greater, less, equal
Another kind of operator
compares.
"Greater, less, equal."
Compare two values
and out comes not a number
but true or false.
"7 is greater than 4" is true,
"7 equals 4" is false.
Compare two values, and true or false. (7 > 4 → true · comparison gives true·false)
A calculation operator
makes a new value,
a comparison operator
gives true or false.
Remember?
Last time "if"
picked a path
with this true·false.
What does this symbol do?
Let's meet the operator symbols
one by one.
What each one does,
laid out in a line.
The adding, the subtracting,
the comparing.
Tap one
and its meaning appears.
Tap a symbol to see its meaning. (Yellow = calculation·new value · blue = comparison·true·false)
There aren't many symbols.
But with these few
you add
and make judgments too.
Each is simple on its own,
but gathered, nothing is beyond them.
Operators are such small tools.
True·false becomes a fork
Why does a comparison operator matter?
Because the true·false it gives
is the fork's switch
from last time's "if."
Compare "is the score 60 or higher,"
and true takes the pass path,
false the fail path.
Compare → true·false → if (fork). (75 ≥ 60 → true → pass)
This is how lesson 6 and 5
connect.
An operator makes the true·false,
and "if" takes it
to pick a path.
One small symbol
grows into a program's judgment.
A hand to make and compare values
An operator
is a hand for handling values.
Add to make a new value,
compare to give true·false.
With this hand
a program calculates and judges.
Next we'll see how to make it
do the same thing many times.
Once you know the symbols, now. (Operator = a symbol to make and compare values → loops · functions · beyond)
Now we've named values (variables),
known their kinds (data types),
judged by comparing (conditions),
and reached calculating (operators).
With these tools stacked one by one
we'll build bigger and bigger things.