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() drivevoid main() {// create a listvar myList = ['d', 'a', 'r', 't'];// using for loop to iterate through the listfor(int i=0;i<myList.length;i++){// checks the index that has the value aif(myList[i] == 'a')continue; // skips the indexprint(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
forloop. We use anifstatement within theforloop to check the index with the valuea. If the condition is satisfied, thecontinuestatement will skip the current execution. Finally, the result is displayed.