Star Student Builder logoStar Student Builder
← Block Builders Lesson 6Std 3-5

Find the Bug

Your program will go wrong. Everybody's does, including the programs written by grown-up engineers. A mistake in code has a name: a bug. Hunting bugs is a skill, and it is mostly about looking carefully rather than guessing.

πŸ’‘ The idea

A bug is a mistake in the code, and finding it is a normal part of coding.

  • The computer always does what you wrote, not what you meant.
  • Read your program one line at a time and say out loud what each line does.
  • Check the numbers first. A wrong turn is the commonest bug of all.
  • Add wait 5 inside a loop to slow the drawing down and watch it happen.
  • Change one thing, run it, and look. Never change five things at once.

πŸ“˜ Words to know

bug
a mistake in a program
debug
find a bug and fix it
test
run the program to see whether it is right

πŸ‘€ Watch this

This was meant to be a square, but it never closes. That gap is the bug.

repeat 4 [ forward 100 right 80 ]
What this program draws
What it draws

✍️ Your turn

  1. Run it and see the gap where the shape should close.
  2. Work out 360 divided by 4, then fix the turn.
  3. Now break it on purpose: change forward 100 to forward 50 on one side only.
  4. Try a different bug: put penup before the repeat and run it. Where did the drawing go?
  5. Write down, in your own words, what each bug did.

🎯 Challenge: Fix the square so that it closes, then use the same idea to draw a closed six-sided shape.

Show me one answer
repeat 4 [ forward 100 right 90 ]
penup
goto -150 0
pendown
repeat 6 [ forward 60 right 60 ]

Your program
Ask GuruAcharya Samayeshwar