Studyfin Studyfin ✨ Sign up free

Comments & code documentation

Grade 6 · Coding · Free lesson

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

When we build programs, we use a design process. We plan our steps, write code, and then test it to solve everyday problems. Sometimes, we need to leave notes to explain how our code works.

school

These notes are called comments. Computers completely ignore comments when they run your program. This means you can write anything you want inside them to help other people understand your code!

x = 5 # This is a comment! print(x) Robot ignores the green comment!

We can write comments in block coding and text coding. In block programs, we attach comment bubbles to our blocks. In text programs like Python, we start our comments with a special symbol like a hashtag.

move_forward() Block Comment: Makes robot move! # Text Comment # This moves robot move_forward() Block Style Text Style
✏️ Worked example

Imagine you want to build a program that automatically waters a plant when the soil is dry. Walk through the design process to create this program with sequence, conditionals, and helpful comments.

  1. Define the problem: The plant needs water only when the soil is dry.
  2. Plan the sequence: First, check the soil moisture. Second, decide to water or wait. Third, wait one hour before checking again.
  3. Add a conditional: Create an 'if' statement. If the sensor reads 'dry', turn on the water pump.
  4. Write the code with comments: Add a comment at the top explaining the goal of the program.
  5. Add inline comments: Place a comment right above the 'if' block to explain that it checks the moisture level.
  6. Review your work: Read the comments to make sure any other student can understand your program instantly.
schoolgirl
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons