In plain words
A loop runs the same piece of code again and again, usually once for every item in a list, until there's nothing left.
Where you see it
Your Chirp feed shows 20 posts, but the code only describes one. A loop runs that description once per post. Cart totals, email batches and "mark all as read" work the same way.
What goes wrong
- Off by one with <=
Lists count from 0, so three items sit at positions 0, 1 and 2. Looping up to <= length reads one past the end and gets undefined.
for (let i = 0; i <= items.length; i++) - A loop that never stops
If the stop condition can never become true, the browser tab freezes and stops responding.
while (page < totalPages) { fetchPage(page); } // page never grows - One database call per item
A loop that asks Supabase about each of 200 posts makes 200 trips. It feels fine with test data and crawls with real users.
What to tell your agent
Quick check
Sign in to earn +10 XP for itA loop over a 3-item order uses i <= items.length. What happens?