Students will be able to...
- Define loop in a programming context.
- Explain why loops are useful.
- Implement simple repeat and forever loops.
- Apply loops to reduce redundancy in scripts.
- Do now 2.1
- 2.1 slide deck
- Exterior angles review
- Lab 2.1 - Squares and triangles Redux (docx) (pdf).
- Looping real world examples
- Example
- Snap! tips: 0, 3, 7, 9, 10, 14, 15, 16, 17
- Video resource: https://youtu.be/XbZqfRGPom0
- Video quiz: See Additional Curriculum Materials accessed from the TEALS Dashboard.
Duration | Description |
---|---|
5 minutes | Welcome, attendance, bell work, announcements |
15 minutes | Lecture and examples |
25 minutes | Squares and Triangles Activity |
10 minutes | Debrief and wrap-up |
Introduce and discuss concepts of code redundancy and readability. Remind students that a program can be written in many different ways that are functionally equivalent.
- Ask students to speculate as to why one version of a program might be better or worse.
- Possible answers: more efficient (in time or space), shorter code, more elegant/readable code.
Show this example to demonstrate unreadable program and give examples on how the repeat blocks (loops) can help make more concise scripting.
- Show students the script, ask what it does, then ask if they can think of ways to improve it.
- Attempt to get students to realize that the script is redundant and could be simplified if there were a way to execute a block of script more than once.
Begin with general definition: A type of block that causes other code to run multiple times in succession.
Use real world loops to introduce the concept:
- Water cycle
- Still I Rise by Maya Angelou
- Happy by Pharrell Williams
The repeat block runs the body of the loop the specified number of times.
- Number of iterations can be a value, variable, or reporter.
The forever block runs the body of the loop nonstop until the script is ended.
It can be stopped either by clicking the stop sign or by any version of Stop Block.
The repeat until runs the body of the loop until the specified condition becomes true.
Save detailed discussion of this loop until conditionals are introduced.
Walk through examples of repeat Block and forever Block
- Emphasize usefulness in reducing redundancy and complexity, especially for repetitive tasks.
Direct students to complete "squares and triangles redux" individually.
- If available, students should use their solutions to Lab 1.3 as a starting point. Ensure students "Save as..." before starting on the new lab to not overwrite their original project (part 1.1).
- If student solutions for Lab 1.3 are not available, or are not correct, provide a correct implementation (the solution to Lab 1.3 can be found on the TEALS Dashboard under Additional Curriculum Materials).
Encourage students to try to use as few blocks and have as little script duplication as possible to draw each shape while still creating understandable scripts.
- Once students complete part 2.1, the remaining parts should go much more quickly as they all follow the same basic pattern.
Discuss one or two student solutions to part 2.2. Ask students to think about what the script would look like without loops.
Discuss one or two students solutions to part 3.1. Point out how unwieldy the script for these two shapes would be without loops.
More advanced students can add additional shapes, including a five-pointed star without interior lines.
Particularly advanced students can be encouraged to build pictures by combining multiple shapes (e.g. a house built of squares of various sizes).
For students struggling with the mathematics, make the exterior angles review available showing various shapes and their respective angles as a reference for students through unit 2.