for each … loop
The for-each loop iterates over all elements in some container/collectible and passes the elements to some specific function.
Syntax:
collection.foreach(void f(value))
Parameters:
- f( value): It is used to make a call to the f function for each element in the collection.
Dart
void main() { var w3wiki = [1,2,3,4,5]; w3wiki.forEach((var num)=> print(num)); } |
Output:
1 2 3 4 5
Dart – Loops
A looping statement in Dart or any other programming language is used to repeat a particular set of commands until certain conditions are not completed. There are different ways to do so. They are:
- for loop
- for… in loop
- for each loop
- while loop
- do-while loop