Coding means writing instructions for a computer. The computer then uses the instructions to do a task. A computer programming language has commands (vocabulary) and syntax (grammar rules and punctuation) for communicating with a computer. As you write code, you put together the commands, using the correct syntax, in a logical way. The logic of your code is the order of the commands and the sequence of what happens due to various conditions. Put together, the instructions that you write and that the computer reads are called the computer program, or just the code.
The first program new coders often write prints the words Hello World! on the computer screen. Here’s the code in Scratch and its output (what it shows onscreen).
Now here’s the same code in JavaScript blocks built in MakeCode and the output on the micro:bit electronics board. Because the micro:bit can scroll only one letter at a time, the figure displays just the letter H at the beginning of the Hello World! message.
You’ll be making little programs like this, and bigger programs too, in no time!
A computer program has lots of parts, such as asking the user a question, doing something with that information, and then telling the user some response. Planning a computer program is a bit like telling a story or running a play in football. You have to put together and execute (run) the program in a certain order.
In each part of a program, you write small chunks of code to do different things. A chunk of code that does a task is called an algorithm. For example, in a paddle ball game, one algorithm you might use is bouncing the ball. If the ball and paddle touch, the player scores a point and the ball changes direction.
What algorithms do you see in games you play on your phone? One algorithm in a Yahtzee game is rolling the dice. An algorithm in a Space Invaders game is flying a spaceship across the sky. You also see algorithms in life, such as a pattern for vacuuming a room or a routine for driving to school. Look for algorithms in the apps you use and in your daily life.
The algorithms you write connect with each other to build your entire program. As coders, we have three fancy terms to describe how we build our algorithms and how they connect with each other: sequence, selection, and repetition. Here’s what each means:
All computer programs have sequence, selection, and repetition. Check back here to refresh your memory of how each is used when coding a program.