Introduction to Programming: Output

Defining Output and how it is used in Programming

Output

It's worth taking a minute to mention output very briefly at this point, as later examples will use it to demonstrate concepts and in explanations. It is very common that we need our code to display something on the screen so we can see what it did. Think of a calculator, if you hit '5 + 5' in your calculator and then hit '=', if nothing displayed on the screen, that wouldn't be very useful! Different languages have different ways of producing output, and there are many different types of output on top of that.

For the sake of this article series, we are going to stick to the most basic form of output, which is console output, often referred to in programming as "standard out" (aka STDOUT). This is where we send data (like letters and numbers) to a console for us to be able to see it. If you'd like to know more about consoles, you can read up more about them in another article, <link: Working with Consoles>, but to define them briefly, they are just an interactive window that allows us to type stuff in and have stuff printed back out for us.

Consoles are a great initial output when learning programming because they are generally very simple to interact with and most languages have very simple ways of doing so. For the sake of the Introduction to Programming articles, we are going to keep it simple and use the following statement to say we want to print out to the console:

print(x);

The "print()" is known as a function, which if you have taken trigonometry, you will have been familiar with functions (such as sin, cos, and tan!), but we will also discuss these more in a later part article <link: Function Basics>. For now, just know that when we type this statement, it will print the value stored in the variable 'x' (or whichever variable we have between the parenthesis) out to the console. So if we had the following code

let x = 5;
print(x);

That would print out a '5' to the console, I know, super exciting, but it's a step toward greater knowledge. Now lets talk a little more about what kind of values we end up sticking in the these variables.

Move on to read about Data Types.