1. Home
  2. /
  3. Uncategorized
  4. /
  5. Iterating Over a Collection

Iterating Over a Collection

How would you calculate how much money you have to spend? Each denomination needs a different value assigned. You compute a running total until you have accounted for all of the bills. For the moment, assume you are uncomfortable carrying large bills, so your wallet or purse contains $1, $5, $10, or $20 bills. The following program represents a “pseudo code” solution to this exercise.

totalCash is a whole number that starts at zero

while (I still have bills left to account for)

     if (current bill is $1)
          add 1 to totalCash
     if (current bill is $5)
          add 5 to totalCash
     if (current bill is $10)
          add 10 to totalCash
     if (current bill is $20)
          add 20 to totalCash

if (totalCash > itemPrice)
     I have enough money to buy the item. 

     I don’t.

This is an example of an iterative method because it is repeated over and over for the entire collection.

Think of a way in which you apply an iterative method to a collection of similar objects in your day-to-day life. Be creative—in other words, identify a situation that does not involve money (either paper or coins). Think about the ways in which the items of your collection are alike, as well as the key ways in which they differ.

By Day 3, post a response that:

  1. Briefly describes your collection and the elements that comprise it
  2. Identifies the characteristic(s) that differentiate(s) the elements of the collection
  3. Briefly describes the method you apply to that collection
  4. Defines the method using pseudo code that contains at least two if methods
Our Essay Format
  • Times New Roman, 12 pt
  • 1 Inch Margins
  • Double/ Single Spacing
  • 275/ 550 Words Per Page
  • MLA/ APA/ Turabian/ Chicago style, etc

A standard double-spaced page contains 275 words

Free Features
  • Hiring a preferred expert
  • Bibliography & cover page
  • Revisions within 14-30 days
  • 24/7 customer support

Place Your Order Now!

No matter what type of essay you need, we’ll get it written, so let’s get started.

Order Now