Looping and Iteration Lab
Lab
Lab time is designed for you to prepare for upcoming lessons, and practice what you have learned so far. Both aspects are important for your success. During this time, you are encouraged to collaborate with fellow students, and reach out to instructors with any and all questions!
Lab Objectives
- Practice using
for
andwhile
loops. - Introduce refactoring by updating a previously completed application.
Practice
Now that we have learned about loops, let’s revisit our restaurant ordering application from last week’s lab. Open your forked copy of the starter repo - we are going to use that as a basis for today’s lab.
Review Prior Implementation
In small groups, discuss your solutions to the restaurant ordering application and brainstorm a few ways we could improve our code. You can use the following sentence starters to get going: * Our current solution repeats this block of code… * Based on what we learned today, we could use __ to reduce the repetition in our solution.
Record key points from your discussion and designate one person from your group to share out.
Implications of Prior Decisions
In your group, discuss the following scenario: Our restaurant now needs to be able to take orders for groups of two. In its current form (without loops), how would we accommodate the need to take orders for groups of two?
A few discussion starters: * To stop asking for third and fourth orders, we might…. * We could _____ to determine group size before asking for an order.
Record key points from your discussion and designate one person from your group to share out.
Re-Implementation (Refactoring)
Using what we have now learned about loops, re-work your implementation to use for
loops and while
loops. In your group, you could each create two implementations, or you could assign a type of loop to individuals. Either way, you should be prepared to discuss either implementation.