break, continue, and Labels
Control loop flow precisely.
break, continue, and Labels is a free Dart Academy lesson on CoddyKit — lesson 4 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.
Steering a Loop
Sometimes you need to stop early or skip a pass. Dart gives you break and continue to steer a loop from the inside. 🕹️
Meet break
The break statement stops the loop immediately and jumps to the code right after it. No more passes will run.
for (var i = 0; i < 10; i++) {
if (i == 3) break;
print(i);
}Stopping on a Match
A common use of break is searching: walk a list and stop the moment you find what you want, saving needless work.
for (var n in nums) {
if (n == target) break;
}Meet continue
The continue statement skips the rest of the current pass and jumps straight to the next iteration of the loop.
for (var i = 0; i < 5; i++) {
if (i == 2) continue;
print(i);
}Filtering With continue
Use continue to skip items you do not care about, like ignoring odd numbers and only acting on even ones.
for (var n in nums) {
if (n.isOdd) continue;
print(n);
}break vs continue
Keep them straight: break ends the whole loop, while continue ends only the current pass and moves on to the next one.
They Affect the Inner Loop
By default, break and continue act on the nearest enclosing loop only. An inner loop cannot stop an outer one this way.
for (var i = 0; i < 2; i++) {
for (var j = 0; j < 5; j++) {
if (j == 1) break; // inner only
}
}Why Labels Exist
To control an outer loop from inside a nested one, you attach a label: a name and a colon placed before the loop.
outer:
for (var i = 0; i < 3; i++) {
// ...
}break With a Label
Writing break with a label exits that named loop entirely, even from deep inside a nested inner loop.
outer:
for (var i = 0; i < 3; i++) {
for (var j = 0; j < 3; j++) {
if (j == 1) break outer;
}
}continue With a Label
A labeled continue jumps to the next pass of the named outer loop, skipping the rest of both inner and outer bodies.
outer:
for (var i = 0; i < 3; i++) {
for (var j = 0; j < 3; j++) {
if (j == 1) continue outer;
}
}Use Labels Sparingly
Labels are powerful but can hurt readability. Reach for them only with nested loops, and prefer a helper function when you can.
Quick Check
Inside a loop you hit continue. What happens next?
Recap
You learned to steer loops: break stops, continue skips, and labels let you target an outer loop from a nested one. 🎯
Frequently asked questions
Is the “break, continue, and Labels” lesson free?
Yes — the full text of “break, continue, and Labels” 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 “break, continue, and Labels”?
Control loop flow precisely. 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 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “break, continue, and Labels” 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
- The Classic for Loop
- while and do-while Loops
- for-in Over Collections
- break, continue, and Labels