Skip to content
KJ Monahan edited this page May 14, 2024 · 1 revision

Class 4: Loops

In the prep work for this lesson, the students learned:

  1. How to write for and while loops:
    1. Proper syntax
    2. Iterating over strings and arrays
    3. Adding a break statement within a loop
  2. When one type of loop is preferred over the other for the following cases:
    1. Known vs. unknown number of iterations
    2. Input validation
  3. The accumulator pattern.

Large Group Time (Instructor Notes)

Announcements

For Part-Time Students:

  1. Reminder of the due date for the first graded assignment.
  2. After this class, the students will have all the skills necessary to complete the assignment.

For Full-Time Students:

  • Welcome to Day 4!
  • As needed

Lesson 4 Topics That Require More Attention

  1. Live coding, live coding, live coding!
    1. Present a sequence of challenges for students, then ask for them to contribute to the solutions presented to the class. Start simple, then increase the complexity of the tasks.
    2. Review how to use increments other than i++ in a loop.
    3. Show how to use a while loop to validate user input.
  2. Tips for avoiding infinite loops and what to do when you create one anyway.
  3. Discuss when one type of loop is preferred over the other.
  4. Emphasize that even though a while loop can be used in place of a for loop, a for loop should NOT be used to replace a while loop.
  5. Studio intro:
    1. Provide a general rundown of what needs to be accomplished with the meal assembly - one meal array for each crew member, and each meal array consists of one item from each of the ingredient arrays.
    2. Encourage the students to try the bonus missions if they finish the main studio content early.

Studio (IA Notes)

  1. This studio contains unit tests, like the Lesson 3 studio.
    1. Students will need to work with multiple functions for this studio. Notes have been provided in the textbook and the starter code.
  2. Common learner stumbling blocks:
    1. The provided starter code contains the entire studio, along with unit tests.
    2. For the self-destruct mission, the examples were carefully chosen to use strings with the same length. If a student wants to use strings of different lengths (which throws an error), help them add some validation to their code to deal with this.
  3. Using a multi-dimensional array helps streamline the process of meal assembly, but students tend to avoid using one. After their code works, encourage them to explore how a 2-D array helps reduce the lines of code.
  4. As always, be sure to check-in with each of your students.