What is the continue keyword in Dart?

The Dart continue keyword

The continue keyword breaks one loop iteration when a certain condition is satisfied.

In a loop, the continue keyword can be used to skip the current execution of the loop block.

Example

The following code shows how to implement the continue keyword in Dart:

// main() drive
void main() {
// create a list
var myList = ['d', 'a', 'r', 't'];
// using for loop to iterate through the list
for(int i=0;i<myList.length;i++)
{
// checks the index that has the value a
if(myList[i] == 'a')
continue; // skips the index
print(myList[i]);
}
}

Explanation

  • Line 2-13: We create the main() function.
  • Line 4: We have a list of strings named myList.
  • Line 5 to 11: We iterate through the list using the for loop. We use an if statement within the for loop to check the index with the value a. If the condition is satisfied, the continue statement will skip the current execution. Finally, the result is displayed.

Free Resources