0Pricing
Dart Academy · Lesson

The Classic for Loop

Count and repeat with an index.

The Classic for Loop is a free Dart Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Dart Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Loops Exist

When you need to repeat work many times, copying code is painful. A loop runs the same block again and again so you write it just once. 🔁

Meet the for Loop

The classic for loop repeats a block a known number of times, using a counter you control from start to finish.

for (var i = 0; i < 3; i++) {
  print('Hello');
}

The Three Parts

A for loop has three parts in its header: an initializer, a condition, and an update. Each is separated by a semicolon.

for (init; condition; update) {
  // body runs each pass
}

The Initializer

The first part runs once, before anything else. You usually declare your counter here, like setting i to 0.

for (var i = 0; i < 5; i++) {}

The Condition

Before every pass, Dart checks the condition. While it stays true the loop keeps going; the moment it is false, the loop stops.

for (var i = 0; i < 3; i++) {
  print(i);
}

The Update

After each pass, the update runs. Writing i++ adds one to the counter so you eventually reach the stopping point.

for (var i = 0; i < 3; i++) {}

Counting Up

Start at 0, stop below your limit, and add one each time. This prints 0, 1, then 2, giving you exactly three passes.

for (var i = 0; i < 3; i++) {
  print(i);
}

Counting Down

Loops can run backward too. Start high, stop above your limit, and use i-- to decrement toward the end.

for (var i = 3; i > 0; i--) {
  print(i);
}

Custom Steps

You are not stuck with steps of one. Use i += 2 in the update to skip ahead and visit every other number.

for (var i = 0; i < 10; i += 2) {
  print(i);
}

Off-by-One Care

Using less-than gives you exactly count passes. Switching to less-than-or-equal runs one extra time, a classic off-by-one bug.

for (var i = 1; i <= 5; i++) {
  print(i);
}

Loop Over a List

A for loop is perfect for visiting items by index. Use length as the limit and read each position with brackets.

var names = ['Ana', 'Bo'];
for (var i = 0; i < names.length; i++) {
  print(names[i]);
}

Quick Check

You want a loop that prints exactly five times. Which header is correct?

Recap

You learned the for loop: an initializer, a condition, and an update working together. Count up, down, or in custom steps with care. 🎯

Frequently asked questions

Is the “The Classic for Loop” lesson free?

Yes — the full text of “The Classic for Loop” is free to read here on the web, and the Dart Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Dart Academy course, upgrade to CoddyKit PRO.

What will I learn in “The Classic for Loop”?

Count and repeat with an index. You practise Dart Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Dart Academy?

No prior experience is required. Dart Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “The Classic for Loop” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Dart Academy lesson?

Yes. Every Dart Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. The Classic for Loop
  2. while and do-while Loops
  3. for-in Over Collections
  4. break, continue, and Labels
← Back to Dart Academy