I am not quite sure what you need help with. If you are trying to get a deeper understanding of control structure, that will probably come at a later chapter. I think the goal of this “Preview” section is to literally preview this concept / feature. It gives you a taste of what’s possible. I don’t think you are expected to have a full understanding of it.
If you do want to get a deeper understanding, that’s awesome too! You can probably look ahead in the text (as long as you don’t get too far and too deep).
Essentially, what is happening here is this:
while loop continuously prompts the user to enter a grocery item.
- The user adds items, one by one. Individually, they get temporarily stored in the
grocery_item variable and then added to the
grocery_list list variable.
done is kind of like an escape word. When the user types it in, the
while loop’s condition evaluates to
False and the loop exits. No more items will be added to the list.
Within the loop,
else work as follows:
if condition is evaluated. If the user’s entry wasn’t the word done, then the else part is executed. The item is added to the list.
- If the user’s entry was the word done, the i
f part does nothing. (The
continue statement within if just does nothing and allows the program flow to continue.) The
while loop goes to the next iteration. Since the word done violates the
while loop’s condition, the
while loop terminates.