Learn

Kenny saw the horrors of the food safety world but rather than those horrors driving him away, he thinks “I can do better!” and decides to take a job as a line cook at a local breakfast spot.

The place is popular and on weekend mornings there is quite a brunch rush. Sometimes Kenny has to make five or more bacon egg and cheese sandwiches at once!

He turns to his knowledge of computer science again. “Well, if I think of the rush as a list of orders, I can iterate through the list and do a step at a time for each sandwich, completing all of the bacon, egg, and cheeses at once!”

So first Kenny puts the eggs for all five sandwiches on the grill, then he iterates through the orders and adds cheese to each one. Next, comes the bacon, he iterates through the list of orders and adds the bacon. Finally, the sandwiches are ready and he plates up each sandwich on a bagel. By iterating through his orders and performing the same operation on each of them, Kenny simplified his cooking process and delivered all five sandwiches on time!

This idea of iteration is essential to computer science and is used in practically every type of application. When you need to perform the same operation on every item in a list, you iterate through the list to complete that task. Almost all algorithms depend on some sort of iteration to produce their results, and by studying computer science you will see not only how to iterate through lists and data structures, but how to iterate efficiently to complete a task in the optimum amount of time.

Instructions

1.

Next Kenny needs to make four omelets!

Consider the code in the editor. Currently, it only contains a list with four elements, all of them representing the eggs for the omelets.

Paste the code below into the editor and click run to iterate through the list to add spinach to each of those omelets!

add_spinach(on_the_griddle)
2.

Nice work! Next copy and paste the code below into the editor to add mushrooms to each of the omelets!

add_mushrooms(on_the_griddle)
3.

Yes, they are smelling good now! Finally, paste the code below into the editor to iterate through the list and add the final topping, cheese, to each of the omelets.

add_cheese(on_the_griddle)

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?