Students will be able to...
- Define and identify: nested for loops, stack trace.
- Use nested loops via a function and a
for
loop. - Use nested
for
loops via an outer loop containing an inner loop. - Use a stack trace to understand and demonstrate the flow of nested
for
loops.
- 4.03 Slide Deck
- Do Now
- Lab - Nested For Loops (docx) (pdf)
- Lab - Caesar Cipher ([docx][https://github.com/TEALSK12/2nd-semester-introduction-to-computer-science/raw/master/units/4_unit/03_lesson/lab_caesar.docx]) ([pdf][https://github.com/TEALSK12/2nd-semester-introduction-to-computer-science/raw/master/units/4_unit/03_lesson/lab_caesar.pdf])
- Read through the Do Now, lesson, and lab so that you are familiar with the requirements and can assist students.
- Video Explanation of nested
for
Loops.
Duration | Description |
---|---|
5 Minutes | Do Now |
10 Minutes | Lesson |
35 Minutes | Lab |
5 Minutes | Debrief |
Duration | Description |
---|---|
5 Minutes | Do Now |
10 Minutes | Review |
35 Minutes | Lab |
5 Minutes | Debrief |
- Display the Do Now on the board.
- Students use nested
for
loops to create a square star pattern.
- Discuss the output of the program - were the students able to guess the output without typing it?
- Go over how to read
for
loops if students are struggling. - Make sure students are understanding loops and string concatenation.
- If students continue to struggle, take 5 minutes to go over the loop syntax and practice.
- Ask a student to write the
print_star_square
function on the board. - Define nested for loop: a loop within another loop.
- For each iteration of the outer loop, the inner loop is iterated through completely.
- Draw a diagram (stack trace) of the
for
loop. - Ask students to draw the nested part of the state diagram (should be inside the outer loop but look the same as the outer loop)
- If students were unable to finish this, give them 5 minutes to practice in groups before calling them back to go over this part.
- Ask a couple of students to write on the board how they did this.
- Ask them how treating the loop as its own function made it easier or harder.
- Ideally this should make it easier as a way of abstracting knowledge of looping.
- The pattern lab asks students to write functions that produce different outputs using nested
for
loops. - The Caesar cipher lab asks students to write a simple letter rotation function which enciphers letter-by-letter, necessitating nested
for
loops.
- Inform students that there will be a Unit 4 Quiz after Lesson 4.04.
- Go over common questions the students had.
- On the second day, if time allows, go over the bonus lab problem and discuss how students solved the problem.
- If students need extra time for lab, there is another day in the schedule for that.
- This topic is often confusing for students new to the concept, so build in time for frequent individual checks for understanding.
- Bonus Lab Problem This is a bit more difficult and should provide a challenge for students who are moving more quickly.