Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Cooking in Batches (Collections & Loops)

So far, we've handled our ingredients one at a time. But a real recipe isn't about a single ingredient; it's about a list of ingredients and a sequence of steps. To cook for real, you need to work with items in batches and perform repetitive actions.

This module is where our simple kitchen prep scales up to a full-blown cooking session. We'll learn how to handle groups of data and how to perform actions on every item in the group without writing the same code over and over.

  • The Pantry (Arrays & Lists): This is where you store all your ingredients. Instead of handling them one by one, you organize them into groups, like all your spices in one jar or all your vegetables in a basket.
  • Stir Until Combined (For Loops): This is like repeatedly stirring a mixture until it's perfectly smooth. You perform the same action (stirring) on different parts of your ingredients, or multiple times, to achieve a desired state, automating repetitive tasks.

Let's start cooking for real.