Lecture 10:  Loops

Activity:  Application Cards



We have seen how to write "for" and "while" loops in lecture.  State one or more applications where you see loops in gadgets, appliances, software, or a task.  Also, state the application of the tool and what type of loop you think this tool uses.  Why did you decide on a "for" loop or a "while" loop?

Here are examples of possible applications:

cooking/kitchen timer
application:  counts down to zero from a time given by user and beeps/buzzes when time has expired
type of loop:  "for", given a time, there are a set number of times the loop which counts down the time will execute

printing a search engine results list
application: list the "hits" found that match key words
type of loop: "for" if the engine looks through entire database or web and then prints out a list of "hits".  This printing is the action executed each time through the loop; "while" if the engine prints results as they are found since the engine doesn't know in advance how many listings should be printed.

A parent packing lunches for his/her family
application:  Each lunch gets a sandwich, fruit, and beverage
type of loop: "for" since the parent packs a lunch for each member of the family.  The number of members in the family is known.  The body of the loop contains the actions of packing a sandwich, fruit, and beverage in each lunch.