LESSON 9

GOAL: Students will be able to…

  1. Create for loops to repeat code a fixed number of times
  2. Explain when a for loop would be a useful tool
  3. Utilize for loops to write programs that would be difficult / impossible without loops

VOCAB:

  1. Loop–A loop is a way to repeat code in your program.
  2. For Loop–A for loop lets us repeat code a fixed number of times.
  3. Control Structure–A control structure lets us change the flow of the code.
  4. Curly Bracket–An open curly bracket is { and a close curly bracket is }
  5. Parentheses–( and )

DO THE FOLLOWING IN ORDER:

  1. REVIEW: 1.8.2 Super Karel Quiz
  2. Think about this: create a function that will enable Karel to climb one stair. What if Karel needed to climb 100 stairs? What part of your code would you need to repeat? What part of you code will be repeated? How many times will the code be repeated?
  3. Watch  1.9.1 For Loops
  4. Look over  1.9.3 Repeated Move
    1. Notice how the condition inside the parentheses works by stating that:
      1. The variable i is initialized, or started at the value of 0.
      2. The i < 9 determines the point that the loop will stop.
      3. i++ increments, or increases the value of i.
      4. All parts in the condition within the parentheses are separated by a semi-colon, expect the last statement
  5. Run 1.9.3 Repeated Move and  1.9.4 Put Down Tennis Balls example and note how the value of i at the bottom of the screen increases and keeps track of how many times Karel has looped through the statement.
    1. Experiment with the code by changing the value of i.
  6. Do  1.9.5 Take ’em All
  7. Do  1.9.6 Dizzy Karel
  8. Do  1.9.7 For Loop Square
  9. Do  1.9.8 Lots of Hurdles
  10. If time permits: In the example exercises Repeated Move & Put Down Tennis Balls, write functions using for loops
  11. FYI: CodeHS Online Textbook–use this as a resource
  12. 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. For loops are a part of all programming languages, why do you think that is?
    2. Why are for loops useful?
    3. For loops extend the limits of what we can do with our programs. What is one Karel program you could write with a for loop that you couldn’t do without one?
    4. Think of and write down three real-life scenarios that could use a for loop.
    5. What did you learn in this lesson/day? How did you learn it? What was your “a-ha!” moment? What sparked it?When did you get stuck? How did you get “unstuck”?

Leave a comment

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