The break and continue statement
Let’s learn how to have more control over loops using the break and continue statements.
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 only want to print the even integers from the list. In this example, however, we only want to know what the first occurrence of an even integer is.
Create a free account to access the full course.
Continue your learning journey with a 14-day free trial.
By signing up, you agree to Educative's Terms of Service and Privacy Policy