Close
Close full mode
logoMakeCode AP CSP

Loops

Summary

Materials

Instructional Activities and Classroom Assessments

  1. Randomness Review (5 minutes)
  2. Introduction to Loops (20 minutes)
  3. Types of Loops (5 minutes)
  4. Revise Your Sprite Stories (20 minutes)
  5. Reflection/Homework

Learning Objectives

  • AAP-2.K For iteration:
    • a. Write iteration statements. 2.B
    • b. Determine the result or side effect of iteration statements. 4.B
  • AAP-2.J Express an algorithm that uses iteration without using a programming language. 2.A
    • For loops- repeat until condition is met.
  • AAP-2.B Represent a step-by-step algorithmic process using sequential code statements. 2.B

Essential Knowledge

  • AAP-2.K.1 Iteration statements change the sequential flow of control by repeating a set of statements zero or more times, until a stopping condition is met.
  • AAP-2.K.2 The exam reference sheet provides:
Text:
REPEAT n TIMES
{
<block of statements>
}
Block:
REPEAT n TIMES
block of statements in which the block of statements is executed n times.
  • AAP-2.J.1 Iteration is a repeating portion of an algorithm. Iteration repeats a specified number of times or until a given condition is met.
  • AAP-2.B.7 Clarity and readability are important considerations when expressing an algorithm in a programming language.

Details

1. Randomness review (5 minutes)

  • What is randomness?
  • What are the kinds of randomness?
  • How is randomness generated?
  • What role does randomness play in games?

2. Introduce Loops (20 minutes)

  • Remind students where they have seen loops used previously in the course.
  • Define loops.
  • Explain the benefits of using loops.
  • Discuss Iteration on the Exam Reference Sheet.
  • Discuss loops in the real world.
  • Give students 5 minutes to work with a partner to create an algorithm for a daily activity that involves iteration.
  • When students are finished, ask them to share their team's algorithm with the class.
  • Task students with animating an image from the sprite gallery.
  • Give students five minutes to create their animation.

3. Types of Loops (5 minutes)

  • Show students what a nested loop is.
  • Demonstrate how students can use the change mySprite by line of code in a repeat loop to create animation.
  • Discuss flip picture.
  • Discuss the types of Loops in MakeCode Arcade:
    • Forever
    • Repeat
    • For index
    • While

4. Revise Your sprite story (20 minutes)

Task students with going back to their Sprite Story and using loops to revise it

  • Students can:
    • Animate their sprites' interactions with each other by creating movement
    • Consider if there is any other way you can use loops to manage the conversations/interactions between the sprites
  • Remind students to share their work and copy the link to the "My Animation Code Segments" page

5. Reflection/Homework

If you run out of time, you may also assign this as individual homework. Students should complete their reflection.

  • How does a repeat block make programming easier by reducing code repetition? Be specific with an example.
  • How can using loops make your code better?
πŸ“˜ Unit 3 - AAP Part 1 β€” Previous
Day 15
Next β€” πŸ“˜ Unit 3 - AAP Part 1
Repetition in Every Day Life