HELLO, WORLD!

It’s customary in the programming world that the very first program you write is called, “Hello, World!” The purpose of this program is simple – have the computer print the words, “Hello, World!” on the screen.

We’re not ones to buck tradition, so we’re going to make “Hello, World!” our very first project. The nice thing about this project is that it’s easy to do (it’s only one line of code) and it will give us an opportunity to start exploring our Integrated Development Environment (IDE).

Here are step-by-by instructions for implementing this project; after we’ve completed it, we’ll talk more about how and why it works.

Step #1: Find the Code Window on Your IDE

All the code you will be writing as part of the RaspberrySTEM projects will be done within the IDE. Specifically, you’ll be writing your code in the Code Window portion of the IDE, which we discussed in the User Guide. As a reminder, here is the Code Window in the IDE:

You’ll notice that at the top left corner of the Code Window, there is a line numbered “1”. This is where you will type in your program’s code:

Step #2: Enter Your Code in The Code Window

It's now time to enter the code for this project.  In the code window, enter the following:

Note that the line number "1" will automatically be visible before you start entering your code, so it's not necessary for you to type the line number.

When you are finished typing that one line of code, press <ENTER> and you should see a prompt for line 2 in your window.

Note: In future projects, the code boxes we present may or may not indicate line numbers next to the lines of code.  Whenever possible, we'll include line numbers to make it easier to ensure that your code is identical to ours; but, in some cases, we'll leave out line numbers to avoid confusion -- this is typically when we're adding new code to existing code and we can't be sure our line numbers will be the same as yours.

Note: It’s important to note that capitalization generally does matter when you’re programming. In this line of code, if the word “print” isn’t in all lowercase letters, you may find that your code doesn’t work as expected.

Note: We mentioned in the Projects Guide introduction that there's a way to cut-and-paste code instead of typing it all in.  As an example of how you do this, you can cut-and-paste the line above right into your code window. To do that, follow these steps:

  1. Highlight the print ('Hello, World!') line in the code box above using your mouse

  2. Press and hold the <CTRL> key on your keyboard and press the letter "C" at the same time -- this copies your text

  3. Click in the Code Window where you want to paste the code

  4. Press and hold the <CTRL> key on your keyboard and press the letter "V" at the same time -- this pastes the text

Step #3: Run Your Code

Now that you’ve typed (or cut-and-pasted) the line of code into the Code Window, let’s see if it works. We do this by “running” the program. To run the program, click on the Play icon () in the Icon menu.

The program runs by starting at the first line, doing what that line says (“executing” that line), and then moving on to the next line. It does that until it reaches the bottom. In this case, we only have one line, so only that line of code is executed.

Step #4: Verify the “Output” of Your Code

If you’ve done everything correctly, you should see the following in your Output Window (the window in the lower left of the IDE, below the Code Window):

Hello, World!
-- PROGRAM FINISHED --

The first line of the output window is the result of the code you’ve written – you’ve successfully had the computer print the words “Hello, World!”

The last line indicates that the program is finished running – this will be helpful later when you’re writing longer and more complicated programs.

Congratulations! You’ve just written your first program!

But wait!  What if the output from your program doesn't look like it's supposed to?  Or if you get a jumbled red and black error-looking message in the Output Window?  If that's the case, you likely have an error in your code.  But, even if your code worked perfectly and you didn't get any errors in your code above, we highly recommend reading the next section, as you're almost certain to encounter programming errors at some point:

Click here to read about Handling Errors in Your Code...

prev| next