Lesson 22: For Loops with Bee

Overview

Featuring Bee, this lesson focuses on for loops and using an incrementing variable to solve more complicated puzzles. Students will begin by reviewing loops from previous lessons, then they'll walk through an introduction to for loops so they can more effectively solve complicated problems.

Purpose

Today's concept, for loops, are a very important topic in computer science. Not only are they widely used, the process of learning for loops enhances the learning of other important concepts (such as variables and parameters.) Students will have plenty of practice critically thinking through problems by determining the starting, ending, and stepping values for each for loop. This concept uses plenty of math as well, so feel free to pair it with a math lesson for an even deeper learning experience.

Agenda

Bridging Activity - For Loops (15 min)

Main Activity (30 min)

Wrap Up (15 min)

View on Code Studio

Objectives

Students will be able to:

  • Determine starting value, stopping value, and stepping value for a `for` loop.
  • Recognize when to use a `for` loop and when to use other loops such as `repeat` and `while` loops.

Preparation

  • Play through the lesson to find any potential problem areas for your class.
  • Make sure every student has a journal.

Links

Heads Up! Please make a copy of any documents you plan to share with students.

For the Students

Vocabulary

  • For Loop - Loops that have a predetermined beginning, end, and increment (step interval).

Support

Report a Bug

Teaching Guide

Bridging Activity - For Loops (15 min)

Previewing Online Puzzles as a Class

Display a puzzle from the lesson. We recommend puzzle #4 because it displays a potential solution and asks the user to evaluate it.

Using a number line, mark the start and ending values of the given for loop (if you aren't using puzzle #4, you will need to come up with a potential solution first). With the class's help, circle the values between the start and end that the for loop will touch. If you are working on puzzle #4, ask the class what they think the answer is to the question, given what they found with the number line.

Main Activity (30 min)

Online Puzzles

Some students may have a hard time differentiating between repeat loops and for loops. We recommend having scratch paper out for students to make guesses on values like the start, stop, and step. Implementing pair programming amongst the class might also be helpful for your students.

Wrap Up (15 min)

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:

  • What was today’s lesson about?
  • How did you feel during today’s lesson?
  • How is a for loop different from a repeat loop?
  • Why do you think for loops could be useful?
View on Code Studio

Student Instructions

View on Code Studio

Student Instructions

Write the code to help the bee collect all of the nectar.

You will need lots of blocks for this challenge, but we'll learn an easier way in the next puzzle.

View on Code Studio

Student Instructions

In this lesson...

Today you'll be learning about a new kind of repeat loop. Here is a preview of the block you'll be using:

Fortunately, this new loop will make solving puzzles like this really easy!

View on Code Studio

Student Instructions

Ah! The use of for loops makes this puzzle a lot easier!

Read the code below. What will happen when you click "Run"?

The bee will move forward and collect all of the nectar from every flower.

The bee will move forward and collect all of the nectar from every flower, except for one.

The bee will move forward and collect one nectar from each flower.

I don't know.

View on Code Studio

Student Instructions

View on Code Studio

Student Instructions

You can also use a for loop to count down.

Try gathering this nectar by counting down from 5 to 1 by 1.

View on Code Studio

Student Instructions

The last number in your for loop is called the "increment". Each time the loop is run, the counter variable changes by the value of the increment.

Try collecting these flowers using an increment of 2.

View on Code Studio

Student Instructions

You've got this!

What should your increment be to collect 3, 6, 9, 12, 15 nectar?

View on Code Studio

Student Instructions

View on Code Studio

Student Instructions

Now, let's combine the counter variable with a math block!

How can you use the counter variable to navigate this garden with the fewest number of blocks possible?

View on Code Studio

Student Instructions

Challenge: Take what you've learned about for loops and try to solve this problem.

Remember: You may have to run through solutions multiple times before you figure out all of the steps.

View on Code Studio

Student Instructions

If your loop is counting down, the increment is subtracted from your counter variable each time through.

What should your increment be to collect 15, then 12, then 9, 6, 3 nectar?

View on Code Studio

Student Instructions

You just learned "for loops"!

For loops are loops where you set the start, stop, and step values.

This new kind of repeat loop gives you more control over when you loop starts, when it ends, and what your loop should increase by every time it runs.

More control means you can solve puzzles a lot faster!


Vocab to Know

For loop - For loops are loops that have a predetermined beginning, end, and increment (step interval)

View on Code Studio

Student Instructions

You can use this for loop to collect all of the nectar. Un-bee-lievable!

There are a few actions that you will want to repeat 'counter' times.

View on Code Studio

Student Instructions

Solve this puzzle with the fewest number of blocks possible.

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
  • MP.8 - Look for and express regularity in repeated reasoning
OA - Operations And Algebraic Thinking
  • 5.OA.3 - Generate two numerical patterns using two given rules. Identify apparent relationships between corresponding terms. Form ordered pairs consisting of corresponding terms from the two patterns, and graph the ordered pairs on a coordinate plane. For example,

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.