Lesson 18: For Loop Fun
Overview
We know that loops allow us to do things over and over again, but now we’re going to learn how to use loops that have extra structures built right in. These new structures will allow students to create code that is more powerful and dynamic.
Purpose
At this point, students have become masters of loops. Today, they will learn about another loop commonly used in programming. The for
loop repeats commands a certain number of times, but also keeps track of the values it is iterating over. For example, a for
loop that begins at 4, ends with 8, and has a step value of 1 will repeat 4 times, but the values 4, 5, 6, and 7 will also be captured for use elsewhere. Using this structure with variables can create some pretty fantastic programs. Today, students will simply be learning the basics of a for
loop before diving into programming with them next time!
Agenda
Warm Up (20 min)
Main Activity (20 min)
Wrap Up (15 min)
Assessment (5 min)
Extended Learning
View on Code Studio
Objectives
Students will be able to:
- Determine starting value, stopping value, and stepping value for a `for` loop.
- Illustrate the counter values hit each time through a for loop during runtime.
Preparation
- Watch the For Loop Fun - Teacher Video.
- Watch the For Loop Fun - Lesson in Action Video.
- Print one For Loop Fun - Worksheet per group.
- Print one For Loop Fun - Assessment for each student.
- Make sure every student has a Think Spot Journal - Reflection Journal.
Links
Heads Up! Please make a copy of any documents you plan to share with students.
For the Teachers
- For Loop Fun - Unplugged Video (download)
- For Loop Fun - Assessment Key - Teacher Key
- For Loop Fun - Teacher Video
- For Loop Fun - Lesson in Action Video
- For Loop Fun - Worksheet Answer Key
For the Students
- For Loop Fun - Worksheet
- For Loop Fun - Assessment
- Think Spot Journal - Reflection Journal
Vocabulary
- For Loop - Loops that have a predetermined beginning, end, and increment (step interval).
Support
Report a Bug
Teaching Guide
Warm Up (20 min)
Vocabulary
This lesson has one new and important word:
- For Loop - Say it with me: For-Loop
Loops that have a predetermined start, stop, and step value.
For One and All
- Point out that there are certain loops that happen very frequently, for example, loops where you need to keep track of how many times you have been through
- Sometimes, you don't want to start with one
- Sometimes, you don't want to count by ones
for
loops give you a powerful way to keep a counter that starts when you want, ends when you want, and increases by whatever size step that you want
Here, you can jump right into a sample of the game (example in English)
Main Activity (20 min)
For Loop Fun - Worksheet
Sometimes we want to repeat things a certain number of times, but we want to keep track of values as we do. This is where a for
loop comes in handy. When you use a for
loop, you know right from the start what your beginning value is, what your ending value is, and how much the value changes each time through the loop.
Lesson Tip
When you play this game, it's as if you're running through a loop like this
for (x=startValue; x <= stopValue; x = x + step){
circle currentXvalue;
add currentXvalue to roundScore;
}
for
Loop block (in English)
Directions:
Lesson Tip
If any of the values rolled are outside the bounds of the game (like rolling a start value of 6 but then rolling 2, 1, 2 for the end value), have the student re-roll everything.
It may be difficult for young students to understand this written in pseudocode, but it may be helpful to have you explain out loud (and perhaps with a diagram) what they will be using as the content of a for
loop.
- Divide students into pairs
- To start the round, each student rolls three times:
- One die to determine the starting value of X
- Three dice to determine the stopping value for X
- One die to determine the stepping value of X each time through
- Use one of the provided number lines to trace the
for
loop that they’ve made- Start at the starting value of X
- Count down the number line, circling the numbers at the rolled interval
- Stop when you get to the predetermined stopping value
- Add all of the circled values to your score, then let the other player take a turn
- Best 2 out of 3 wins
Wrap Up (15 min)
Flash Chat: What did we learn?
Lesson Tip
Flash Chat questions are intended to spark big-picture thinking about how the lesson relates to the greater world and the students' greater future. Use your knowledge of your classroom to decide if you want to discuss these as a class, in groups, or with an elbow-partner.
- What would your interval need to be if you wanted to count from 4 to 13 by threes?
- What kinds of things do you think you could do with a for loop?
- Can you reproduce a normal loop using a for loop?
- What would you need to do?
Journaling
Having students write about what they learned, why it’s useful, and how they feel about it can help solidify any knowledge they obtained today and build a review sheet for them to look to in the future.
Journal Prompts:
Assessment (5 min)
For Loop Fun - Assessment
Hand out the assessment worksheet and allow students to complete the activity independently after the instructions have been well explained. This should feel familiar, thanks to the previous activities.
Extended Learning
Use these activities to enhance student learning. They can be used as outside of class activities or other enrichment.
Run it Backward
- Try this activity again, but this time have the start number be selected using three dice, and the stop number with only one. Make sure to have a negative increment!
Hop Scotch
- Using chalk, draw a hop scotch diagram outside on the blacktop
- Number the squares from bottom to top
- Have students give each other a start square, stop square, and how many at a time they need to jump
- When the jumper is done, have them write down the loop they just performed
- Start adding additional activities to be done at each square, this will add complexity to the written portion, as well
- Levels
- 1
Student Instructions
Standards Alignment
View full course alignment
CSTA K-12 Computer Science Standards (2017)
AP - Algorithms & Programming
- 1B-AP-09 - Create programs that use variables to store and modify data.
- 1B-AP-11 - Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process.
Cross-curricular Opportunities
This list represents opportunities in this lesson to support standards in other content areas.
Common Core English Language Arts Standards
L - Language
- 5.L.6 - Acquire and use accurately grade-appropriate general academic and domain-specific words and phrases, including those that signal contrast, addition, and other logical relationships (e.g., however, although, nevertheless, similarly, moreover, in addition).
SL - Speaking & Listening
- 5.SL.1 - Engage effectively in a range of collaborative discussions (one-on-one, in groups, and teacher-led) with diverse partners on grade 5 topics and texts, building on others’ ideas and expressing their own clearly.
- 5.SL.1.a - Come to discussions prepared, having read or studied required material; explicitly draw on that preparation and other information known about the topic to explore ideas under discussion.
- 5.SL.4 - Report on a topic or text or present an opinion, sequencing ideas logically and using appropriate facts and relevant, descriptive details to support main ideas or themes; speak clearly at an understandable pace.
- 5.SL.6 - Adapt speech to a variety of contexts and tasks, using formal English when appropriate to task and situation.
Common Core Math Standards
MP - Math Practices
- MP.1 - Make sense of problems and persevere in solving them
- MP.2 - Reason abstractly and quantitatively
- MP.4 - Model with mathematics
- MP.6 - Attend to precision
- MP.7 - Look for and make use of structure
OA - Operations And Algebraic Thinking
- 5.OA.2 - Write simple expressions that record calculations with numbers, and interpret numerical expressions without evaluating them. For example, express the calculation “add 8 and 7, then multiply by 2” as 2 × (8 + 7). Recognize that 3 × (18932 + 921) is three t
Next Generation Science Standards
ETS - Engineering in the Sciences
ETS1 - Engineering Design
- 3-5-ETS1-1 - Define a simple design problem reflecting a need or a want that includes specified criteria for success and constraints on materials, time, or cost.