BEGIN:

LESSON 12

GOAL: Students will be able to…

  1. Explain the purpose of a while loop
  2. Create while loops to repeat code while a condition is true
  3. Utilize while loops to solve new types of problems
  4. Test their solutions on different Karel worlds

VOCAB: 

Loop A loop is a way to repeat code in your program.
While Loop Lets us repeat code as long as something is true.
Condition A condition is code that you put inside an if statement or while-loop.
Control Structure A control structure lets us change the flow of the code.
Fencepost Problem A problem when using a while loop where you forget one action at the beginning or the end.

DO THE FOLLOWING IN ORDER:

  1. REVIEW:
    1. Do  1.11.2 If/Else Statements Quiz
    2. What do we know about for loops?
    3. In what situation would for loops not be helpful?
  2. Do Now: Write instructions that will allow me (the teacher) to clap at the same time as walking. Use a conditional statement or for loop if necessary.
    1. Be prepared to share your instructions with the class.
    2. I will execute the commands exactly as they are read.
  3. Introducing the concept of a while loop: we wanted to achieve clapping while we were walking, thus we can use a while loop.
  4. Watch 1.12.1 While Loops in Karel
  5. Get a copy of While loops (student-version) and begin working on the activity.
    1. After you have completed the activity in the handout, how would a for loop would be written for the activity? How reusable would our code be if Karel’s world became a 4×2 world, or a 5×5 world?
      It is important to remember about writing reusable code, so that if Karel’s world changed, how useful would a for loop be if Karel’s world decreased to 4×2 or a 5×5?
  6. 1.12.3 Move to Wall demonstrates this concept by changing Karel’s world from 6×6, to a 8×8 and 10×10.
  7. Go over the Why Use Loops? handout–get it from your teacher.
  8. SHOW ME WHEN YOU ARE DONE: Work individually or in pairs to complete:
    1.  1.12.4 Follow The Yellow Ball Road
    2. 1.12.5 Lay Row of Tennis Balls: Get the Fence Post Handout from your teacher to possibly help you
    3. 1.12.6 Big Tower
  9. Be sure to use debugging strategies so that your code is reusable in all of Karel’s worlds.
  10. FYI: CodeHS Online Textbook–use this as a resource
  11. BEFORE YOU LEAVE, WRITE ABOUT THE FOLLOWING in the Word Online file named Web Apps & Coding for this class (you will write in this file daily):
    1. What is the difference between for loops and while loops?
    2. Provide an example of when you would use each loop.

Leave a comment

Your email address will not be published. Required fields are marked *