Displaying Output
“Hello, World!”
What is Output?
The goal of every algorithm is to solve a problem—recall an algorithm is just a list of steps to solve a problem, and to every problem there is a solution. It is necessary, though, not only to find the solution, but to communicate that solution out of the program. After all, how useful would a calculator be if it calculates the answer to some arithmetic operation but does not tell you its results? It is, therefore, necessary that our first step to learning to program is learning how to create output.
Display Hello World
In CSP output is generated via the use of the DISPLAY function (do not worry yourself
about what a function is at this point yet). In order to output “Hello, World!” simply
write DISPLAY then within parenthesise write "Hello, World!" like so,
DISPLAY("Hello, World!").
Try typing DISPLAY("Hello, World!") below then pressing RUN.
Notice that the output appears at the bottom of the block we just ran.
Displaying Other Values
As you can probably guess, we can display much more than “Hello, World!” We can place any text between the two quotes in order for it to be displayed.
We may also have multiple DISPLAY commands.
Whenever we print out text, it must be surrounded by quotes. This is not the case for
two special kinds of values, though. Numbers can be printed directly as well as the
values true and false. We will explore what makes these values special in the next
lesson when we talk about data types, but for now, note that DISPLAY can work directly
on them.
Try switching the false with true.
Next: Datatypes & Variables