App development · lesson 19 of 24 · free

Loops over lists — App development for students

Apps are full of lists: scores, steps, names, messages. A loop repeats code once for each item, so three lines of code can handle a list of any length. A for loop with i going from 0 up to the list’s length visits positions 0, 1, 2 and so on to the last item. Inside the loop you can add up a total, count the items that pass a test, keep the biggest value or show each name in turn.

▶ Watch how it works

Got it? Practise ↓

Developer's tip

One by one — “the loop visits positions 0, 1, 2 … up to the last item”

  1. for (let i = 0; i < list.length; i++) visits every item, from position 0.
  2. Total: add each item. Count: add 1 when the test is true. Best: keep the biggest so far.
  3. The body runs once per item: a list of 5 runs it 5 times.

Use it for: Adding scores, counting passes, finding high scores and showing lists of names.

Worked example: 🔁 What number does this code show?
let steps = [8, 15, 13, 9];
let total = 0;
for (let i = 0; i < steps.length; i++) {
  total = total + steps[i];
}
show(total); → 45

  1. The loop adds every item to total.
  2. 8 + 15 + 13 + 9 = 45.

Check: 45 − 9 − 13 − 15 = 8 ✓

▶ Watch it animated

✏️ Practice

Work it out in your head or on paper, type the answer and press Check. Stuck? Press “Show me how”.

Right: 0 · Tried: 0

🏁 Lesson 19 test

20 questions. Check each answer, then go to the next one. Get 16 or more right to pass.

🏅 Sign in with Google to earn the 🔁 List Loop Runner badge when you pass — and a certificate when you finish all 8 lessons of Part 3 · Logic and Building. You can still take the test without signing in.

🖨️ App Dev Worksheet: Loops over Lists

✨ Free AI tutor

Ask the AI tutor about this lesson

Why does it work? When should you use it? Ask in English, मराठी or हिंदी.

Sign in with Google to ask Free — 20 questions a day.

👩‍🏫 App development classes near you — online or at home

Prefer a real teacher? TalentJR teachers take live online classes anywhere in India and visit homes in selected cities. Tell us what you need and our team will call you with timings and fees.

Live online classesSmall groups or 1:1 with a teacher, from home, any city.
Teacher at homeA TalentJR teacher visits your home (selected cities).
At a centreClasses at a TalentJR partner centre near you, where available.
Badges, certificates & gifts A badge for every lesson you pass, a certificate for every part you finish, plus TalentJR Points for daily practice. HTML, CSS & web development Build web pages with HTML, CSS and a little JavaScript.