while Loops
Now that you have a unique list of patrons, you will have them randomly place their orders from the menu.
In this section, however, you will use a different control flow mechanism for looping through a collection: a while loop.
for loops are a useful form of control flow when you want to run some code for each element in series.
But they are not as good at representing state that cannot be iterated through.
That is where while loops are useful.
A while loop’s logic is, “While some condition is true, execute the code in this block.”
You are going to generate exactly 10 orders by using a var to keep track of how many orders have been generated and a while loop to continue generating orders until 10 have been placed.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access