Skip to main content

break & continue

Dart supports two loop control statements:

  • break
  • continue

They can be used inside the for, while, or do while loops to terminate the loop or jump to the next iteration.

The break statement

The break statement terminates the loop and continues with the program execution.

In the following example, we use the break statement to terminate the for loop when the value of the variable i equals 5: i == 5.

As we can see, the for loop did not print the numbers 5, 6, 7, 8, 9, and 10 because it was terminated early by the break statement.

The continue statement

The continue statement terminates the current loop and continues with the next iteration.

In the following example, we use the continue statement to terminate the for loop and continue with the next iteration when the value of the variable i equals 5: i == 5.

As we can see, the for loop did not print the number 5 because the iteration was terminated by the continue statement, and unlike the break statement, the numbers 6, 7, 8, 9, and 10 were printed.