What is "continue" in Dart?

Mon, Dec 19, 2022

Read in 2 minutes

In this post we take a look at "continue" keyword with some example codes.

In Dart, continue is a keyword that is used within loops to skip over the current iteration and continue with the next one.

When a continue statement is encountered within a loop, the program immediately jumps to the next iteration of the loop, skipping any remaining code in the current iteration.

The continue statement is typically used in loops that iterate over a collection of items or perform a set of actions a certain number of times. By using continue, you can skip over certain items or actions that meet a specific condition.

Here is the general syntax for using continue in a loop:

for (var i = 0; i < limit; i++) {
  // some code
  if (condition) {
    continue;
  }
  // more code
}

In this example, the continue statement is used within a for loop that iterates over a set of items. If the condition is true, the continue statement is executed and the current iteration of the loop is skipped. If the condition is false, the loop continues with the next iteration.

Here is an example that demonstrates how to use continue to skip over certain items in a list:

var list = [1, 2, 3, 4, 5];
for (var item in list) {
  if (item.isEven) {
    continue;
  }
  print(item);
}

In this example, the loop iterates over a list of integers. If an item in the list is even, the continue statement is executed and the loop skips over that item. If the item is odd, the loop continues and prints the item to the console.

The output of this code will be:

1
3
5

In summary, continue is a keyword in Dart that is used within loops to skip over the current iteration and continue with the next one. It is useful for skipping over certain items or actions in a loop based on a specific condition.


Shohruh AK



Category:

Dart

Tags:



See Also

What is "class" in Dart?
What is "case" in Dart?
What is "break" in Dart?
What is "async" in Dart?
What is "assert" in Dart?