AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Loops repeat for us

Week 1 · Unit 1: Be an animator · 3 lessons
3

Notes called comments

Computing 4: Unit 1, pp. 8–19
GoalExplain what a comment is and why programmers add comments.
New words
comment · a note in a program that explains the code; the computer does not run itbug · a mistake in a programdebugging · finding and fixing the bugs in a program
Explanation

A comment is a note written in a program to explain what the code does. The computer does not run a comment, so a comment never changes what the sprite does. Comments help other people to read your program, and they help you when you come back to it later. They also help with debugging, because you can check that each block does what its comment says. In Scratch, right-click a block and choose Add Comment. On a tablet, press and hold the block. A yellow note appears and you type your words in it. Good comments are short, such as “start place” or “short pause so we can see”.

BlockComment
go to x: (0) y: (−100)start at the bottom
foreverrepeat until we stop
change y by (10)go up a little
wait (0.1) secondsshort pause so we can see
Worked examples
whenclickedgo to x:0y:-100change y by10wait0.1secondsforever
This is the rocket program that the comments belong to. The rocket starts near the bottom and moves up 10 steps every 0.1 seconds, again and again, until it reaches the top edge of the stage and cannot go any higher.
A: no commentwhenclickedmove10stepsB: comment says “move 100 steps”whenclickedmove10steps
A comment is not code. In program B the block has a comment that says “move 100 steps”, but the block says 10. The sprite does the same in both programs: it moves 10 steps.
whenclickedsayHello!for1secondswait0.2secondssayBye!for1seconds
A comment can help to find a bug. Mia’s comment says “wait 2 seconds”, but the block says 0.2. “Bye!” pops up almost straight after “Hello!”. The comment shows what she meant, so she fixes the block to say 2.
Class activity

Sticky-note comments (with a friend): write a program with five blocks on paper, one block on each line, for example when green flag clicked, go to x: 0 y: 0, forever, next costume, wait 1 seconds. Your friend writes a comment on a sticky note for each block and sticks it next to it. Swap roles. Then read the comments aloud: does each one tell the truth about its block? Can you find a comment that is wrong? If you have a computer or tablet, add a comment to a block in Scratch.

Practice
1
What is a comment in a program?
2
The block “move (30) steps” has a comment that says “move 300 steps”. The sprite starts at x: 0 and faces right. Where is it after the green flag is clicked?
The last block has the comment “move 300 steps”whenclickedgo to x:0y:0move30steps
3
Write a short comment for each of these three blocks.
whenclickedgo to x:-120y:0next costumewait0.3secondsforever
4
Give two reasons why comments are useful.