CS105      Lab 7 - Loops

Objectives:

  1. Before starting this lab you should have read Chapter 7 in your text.
     
  2. Section 7.1 in your text describes a counting loop and nested loops  This is illustrated by getting a bunny to hop eight times.  Instead of duplicating the hop code eight times, we can put that code in a counting loop.  Feel free to try that code out yourself on pp213-216 of your text.
     
  3. It is possible to have a loop INSIDE another loop.  This is called a nested loop and an example of this is given on pp211-213.
     

  4.  
    Assignment:
    Implement code to get the bunny to hop in a square by using nested loops as described on p 230 #2.


     

  5. Assignment:
    Reuse your combo lock from lab4.2 to implement the Lock Combination scenario described on p230 #4


     

  6. We may not have a count for how many times we want to loop.  Instead we might want to loop as long as some condition holds.  This is a while loop and an example is given  on pp219-224 where a shark is chasing a goldfish.  We want to continue (loop) the chase as long as the condition that the shark is more than a certain distance from the goldfish is true.  Feel free to try this code out.

     

  7.  

    Assignment:
    Implement the Frog and the Ladybug scenario as described on p231 #5.

     

     

  8. Send your worlds to me in GoucherLearn.