Lesson 3.2: Combining Loops and Conditionals

Learning Objectives

Students will be able to…

  • Combine loops with conditionals to create models with repeated but conditional behavior.

Materials/Preparation

Pacing Guide

Duration

Description

5 minutes

Welcome, attendance, bell work, announcements

10 minutes

Review, lecture and introduce activity

30 minutes

Gravity activity

10 minutes

Review and wrap-up

Instructor’s Notes

Review and lecture

Review loops and conditionals

  • Ask students what loops do, when they are useful, and what loops exist in Snap!.

    • Loops cause code to execute multiple times.

    • Loops can help reduce redundancy and increase readability.

    • Snap! contains three loops: repeat, forever, and repeat until.

  • Ask students what conditionals are for and when they are useful.

    • conditionals are used to execute a block of code only under certain circumstances.

    • Encourage discussion about previous activities.

    • Fill in understanding gaps when necessary.

Demonstrate combining loops and conditionals

  • Present repeat until and forever if blocks.

    Repeat Until Block

    Forever Block

  • Ask students to suggest when these constructs might be useful.

    • repeat until is useful when a loop needs to run not for a set number of iterations, but until some situation occurs.

    • forever if is useful when a script should execute any time a condition is true, for the duration of the program.

    • Point out that the condition in repeat until is a termination condition, while in forever-if it is a continuation condition.

Introduce the concept of modeling

  • Modeling: building a system to simulate the behavior of a real-life phenomenon by simplifying or ignoring certain details.

  • Ask students to suggest systems or concepts that might need to be modeled.

  • Discuss important considerations when designing and implementing a model.

    • Lead students to realize that most sacrifice some amount of accuracy or realism for simplicity.

Activity

  • Students should complete “What Goes Up…” lab individually.

  • Mention that the script written in this lab will be helpful for the end of unit project.

Debrief

Accommodations/Differentiation

  • Take care to ensure that all students have a functional script by the end of the lab to avoid putting some students at a disadvantage starting the project.

  • If many students struggle, consider releasing your own solution after the lab has been completed in class.

  • Ask the more advanced students to assist struggling students. It is vital that all students complete this lab in advance of starting the project.

  • Advanced students can consider increasing the realism of their gravity model by adding acceleration and/or beginning to implement jumping.

Forum discussion

Lesson 3.2 Combining Loops and Conditionals (TEALS Discourse account required).