Studyfin Studyfin ✨ Sign up free

Comments & code documentation

Grade 4 · Coding · Free lesson

Hi there! I am Studyfin, your coding buddy. Today, we will learn how to write secret notes in our code that only humans can read!

When we build a program, we write instructions for the computer. But sometimes, we need to leave notes for ourselves or other people. These notes are called comments.

arduino

The computer completely ignores comments when it runs your program. This means we can explain how our loops, events, and conditionals work without breaking the code.

start() # This is a comment! # Robot ignores this move_forward()

We use a special symbol to start a comment, like a hashtag. When the computer sees this symbol, it skips all the way to the next line of code.

# Skip this line!
✏️ Worked example

Imagine we want to build a simple block program that makes a character jump when they touch a gold coin. Let's use a design process to write this program and add comments to explain our steps.

  1. First, we plan. We need an event for when the character touches the coin, and a sequence to make them jump.
  2. Next, we write our first comment to explain the goal: '# Make character jump when touching coin'.
  3. Then, we create the event block: 'When character touches coin'. This tells the program when to start.
  4. Inside the event, we add a comment to explain the action: '# Move up and down to jump'.
  5. Now, we add the action blocks: 'Move Up 10 steps' and then 'Move Down 10 steps'.
  6. Finally, we test our code. The character jumps, and our comments help anyone reading the code understand exactly why!
schoolgirl
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons