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

Similar Reads

for loop

For loop in Dart is similar to that in Java and also the flow of execution is the same as that in Java.Syntax:...

for…in loop

...

for each … loop

For…in loop in Dart takes an expression or object as an iterator. It is similar to that in Java and its execution flow is also the same as that in Java....

while loop

...

do..while loop

The for-each loop iterates over all elements in some container/collectible and passes the elements to some specific function....