How to use the
Learning Portal

Learning Portal

Our hands-on, comprehensive lesson plans span a range of levels. Browse our free STEM and coding learning resources.

Marty Image

1.09: Tidy Up the Code with Repeat Blocks

45 Minutes

Lesson Overview

In this lesson, students will continue to build upon their programming knowledge using repeat blocks, or loops, with MartyBlocks. Students will understand that they can use loops to reduce the number of lines of code that they have to write by the end of the lesson through using a combination of computational thinking and the MartyBlocks editor.

Key vocabulary:
    Code blocks, Loops, Repetition,

Content Sections

  • Learning Objectives
  • Warm Up
    • Get Learning
      • Unknown block type "figure", please specify a serializer for it in the `serializers.types` prop
        Unknown block type "youtube", please specify a serializer for it in the `serializers.types` prop
      • Time for Practice
      • Unknown block type "youtube", please specify a serializer for it in the `serializers.types` prop
      • Cool Down
        • Extensions & Challenges
        • Extend
        • Support
        • Additional Reading
        • 1.09: Tidy Up the Code with Repeat Blocks

          45 Minutes

          Lesson Overview

          In this lesson, students will continue to build upon their programming knowledge using repeat blocks, or loops, with MartyBlocks. Students will understand that they can use loops to reduce the number of lines of code that they have to write by the end of the lesson through using a combination of computational thinking and the MartyBlocks editor.

          Key vocabulary:
            Code blocks, Loops, Repetition,
          • Awareness of some block names, awareness of planning diagrams
          • iPad or Tablet with MartyBlocks
            • Marty the Robot v2
            • Tablets
            • Access to the MartyBlocks editor

          Learning Objectives

          • I can identify a repeat block
          • I can use a repeat block to make my program smaller and easier to explain

          Warm Up

          Share the objectives and success criteria from the presentation.

          Play the word game that requires learners to repeat everything that everyone says before them:

          • my name is John and I like jaguars,
          • my name is Lisa and I like lemons and this is John and he likes jaguars
          • my name is Ashley and I like apples, this is Lisa and she likes lemons and this is John and he likes jaguars.

          Depending on class size, it might be wise to have this done in smaller groups so that less time is taken. The idea of the game is to get used to things repeating.

          Read the story text from the presentation. When you reach the section on planning and comparing the blocks between MartyBlocks Jr and MartyBlocks, have learners engage with the group tasks in their workbooks.

          Get Learning

          Have learners look at and discuss two of the repeat blocks in the Control section:

          • what they do differently;
            • one has an argument that allows you to set the number of times the code will repeat and the other will only end when the stop icon is pressed (there are other ways to stop the forvever repeat block but it is suggested that you do not mention more, yet, as they are more complex).
          • what they do that is the same;
            • they both repeat the code, within the block
          • when you would want to use one instead of the other;
            • when you want the repeat to occur a specific number of times vs when the number of times is not important
          • when you would have to use one over the other, when one has a limitation that wold cause problems in a program.
            • when repeating too often would cause Marty to walk over an edge or into an obstacle

          The presentation shows two examples of code the village children have created in MartyBlocks. After time for learners to discuss how they think they would improve the code, a mouse click will reveal an example for a more efficient version, which makes use of the repeat block. Do not limit the discussion to this as the only correct answer. Encourage learners to compare any contrasting thoughts they may have had with what is presented on the slide.

          Show learners the plan that the village children used for one of the code comparisons: repeat block-free code and repeat block code. Explain how the rhombus shape indicates what the repeat block will do: the arrow controls the flow for the program, the repeat block will go back to an earlier block of code, and everything, after where the arrow points, is repeated. The teacher guide explains this with the examples beside the plan without a repeat.

          Here is a very basic block of code with Marty acting to it.

          Time for Practice

          The next slide will show a very basic example of a plan and code without the repeat block, and a video of Marty carrying out the code, and the transformed plan and code with the repeat block. The updated code with the repeat block is displayed, below.

          Have learners consult their workbooks. In it, they will find three plans, without any use of the shape for the repeat block. Challenge learners to rewrite the plan, using the rhombus shape to indicate where the repeat would interact with the code. Then, have learners create the code in MartyBlocks and test the code in action; does it do what the plan asks? The updated plan with the associated code blocks are in the teacher guide.

          This will require a bit of time for learners to discuss, plan and test.

          Cool Down

          Bring learners back together to discuss the challenges they faced and overcame. Have groups model their creations and explain what is happening, when. Encourage other groups to compare their work and ask questions to deepen their understanding of the processes.

          Suggested questions you might ask:

          • Do you prefer the repeat block in MartyBlocks or MartyBlocks Jr (if applicable)
          • Do you prefer reading code that has the repeat block or does not have it?
          • What challenges did you face when converting from repeat-free plans to plans and code with repeats.

          Carry out any end of lesson routines.

          Log off devices and clear everything away.

          Extensions & Support

          Extend

          Challenge learners to include two separate loops within a program with an action to separate the two blocks.

          Support

          Have cut-outs of the planning shapes to support arranging them, first, then learners could trace or copy their physical plan. The emphasis has to be on the plan making sense and taken from the shapes looking perfect. Alternatively, you may want to prepare sufficient shapes to allow learners to glue them into the workbook.

          Additional Reading

          • Marty the Robot Educator Guide
          • Educator FAQ

          • Technologies: Computing Science
          • Literacy & English: Listening and Talking
          • Health and Wellbeing: Mental, Emotional, Social and Physical Wellbeing
          • Literacy & English: Writing
          • CSTA Education Standards
          • Elementary Technology Applications: Grade 3 to Grade 5
          • Digital Technologies, Design & technologies: Design & Technologies
          • Digital Technologies, Design & technologies: Digital Technologies
          • Computing, Design and Technology: Computing
          • International Society for Technology in Education (ISTE)