Numbers, text, true and false
We put values in boxes and showed them on screen. But is that value a number, or text? Values have kinds too. What you can do with one depends on its kind.
Values come in three main kinds
A value in a variable
isn't just anything;
it has a kind.
A number you can calculate with,
text made of letters,
and true or false.
These three kinds
are the basics of values
a program handles.
The three kinds of value.
A number is just 25,
text is "Minjun" wrapped in quotes,
true·false is one of two.
The shape itself
tells the kind.
The computer too looks at the kind
and treats the value differently.
Even adding differs by kind
The same "add"
means something different
by kind.
Add numbers
and it's calculation,
but add text
and it sticks together.
The kind decides
what gets done.
The same + gives different results by kind.
3 plus 4 is 7,
but add "4" to "3"
and you get "34".
As numbers it's calculation,
as text it's sticking together.
The same +,
but the kind changes the result.
"3" and 3 are different
To the eye it's the same 3,
but with quotes it's text,
without them it's a number.
Text "3"
can't be calculated.
Only the number 3 can.
Toggle the quotes on and off
and watch how 3 plus 4
changes.
One quote mark changes the kind.
One quote-mark's difference
makes it calculate
or stick together.
So if you confuse the kind,
the program
behaves strangely.
"3" and 3
look the same but are different values.
True and false are the third kind
The third kind
is true and false.
"Yes" and "no,"
a value with just two options.
Last time the ALU
answered "is 10 bigger than 7"
with true,
that's exactly this kind.
A value that's one of two.
True·false
has only two options,
so it's simple,
but it's the most important kind.
The "if this is so"
we'll see next time
chooses a path
with exactly this true·false.
The kind has to fit to go in
A box (variable) too
can have a kind set.
Say "only numbers in this box,"
and when you try to put text,
it tells you it doesn't fit.
Put in a value
and switch the box's kind
to see if it matches.
Check whether the box's kind and the value match.
Setting a kind
prevents mistakes
from a wrong value going in.
Numbers in a number box,
text in a text box.
Each value has a kind,
and keeping that kind
is a basic of programming.
Next time we'll make
a fork in the road
with this true·false.