You've learned the differences between for
and while
loops. Now let's practice recognizing which scenarios call for each type of loop.
Engagement Message
Ready to become a loop selection expert?
Type
Multiple Choice
Practice Question
Which loop would be best for this scenario: "Print all items in a shopping cart"?
A. for...of loop (for each item in the cart) B. Traditional for loop (counting from 0 to cart length) C. while loop (until condition changes) D. Both A and B would work well
Suggested Answers
- A
- B
- C
- D - Correct
Type
Fill in The Blanks
Markdown With Blanks
Fill in the blanks to choose the right loop keywords:
Suggested Answers
- for
- while
- for...of
- do...while
Type
Sort Into Boxes
Practice Question
Sort these programming tasks into the correct loop type categories:
Labels
- First Box Label: Definite (for loop)
- Second Box Label: Indefinite (while loop)
First Box Items
