Search⌘ K

The break and continue statement

Explore how to control loop execution in Dart by using break to exit loops early and continue to skip specific iterations. Understand their practical use cases with examples that help you manage conditions within loops to write efficient Dart code.

We'll cover the following...

The break Statement

The break is used for prematurely stopping a loop. When Dart finds a break statement, it breaks from the loop regardless of whether the iterations have been completed or not.

It’s mostly used with a conditional statement. Based on the condition, the loop will either need to exit or not.

Let’s look at an example similar to the one we looked at with for-loops, where we have a list of integers and we ...