How do we exchange values?
Last time we put a value in a box. But how do we see that value, and how do we put in a new one? Let's look at the two directions we and a program exchange.
A conversation has two directions
Just as people talk,
we exchange
with a program too.
The computer
showing us something,
and us
putting something into the computer.
These two directions
are the communication of every program.
Between the computer and us, two directions.
What the computer shows
is called output,
what we put in
is called input.
With just these two
you can have any conversation
with a program.
Output puts a value on the screen
First, output.
Showing a value the program has
on the screen.
Remember that box (variable)
we made last time?
Say "show the value in the name box,"
and that value
appears on the screen.
Press the button.
Output a variable's value to the screen.
Thanks to output,
we can see with our eyes
the values inside a computer.
Calculation results,
stored information,
if we don't output them
we have no way to know.
Input takes a value and puts it in a box
The opposite direction is input.
When we put in letters or numbers,
that value goes into a variable.
"Take the name as input
and put it in the name box."
Like this.
Input always leads
to being held in a box.
Try putting one in.
The value you input goes into a variable.
Thanks to input,
a program listens to us.
Even the same code
behaves differently
by the value you put in.
Like greeting you by name
once you put your name in.
Take turns and it becomes a conversation
Take turns with output and input
and a real conversation begins.
The computer asks (output),
we answer (input),
the computer answers back (output).
This give-and-take
is the basic skeleton
of every app we use.
Ask (output), answer (input), answer (output).
Chat apps,
games,
the search box,
are all really this.
The back-and-forth
of output and input.
There's just complex stuff
stacked on top.
A program that takes input and greets
Now combine the two
and make a small program.
Take a name and age as input (input),
use them to make a greeting
and put it on the screen (output).
Put in values
and press run.
The result is made
from what you input.
Input → process → output.
Take a value with input,
make something with that value,
show it with output.
This flow is the basics of a program.
Next time we'll look into
whether these values are numbers or letters,
their kinds.