dart list for loop code example

Example 1: foreach loop in list in dart

main() {
    List<String> list = new List<String>();
    list.add('one');
    list.add('two');
    list.add('twelve');
    list.forEach((element) => print(element));

    Set<String> set = Set.from(list);
    set.forEach((element) => print(element));    
}

Example 2: dart for in loop

void main() { 
   var obj = [12,13,14]; 
   
   for (var prop in obj) { 
      print(prop); 
   } 
}

Example 3: dart loop through array

for (var i = 0; i < list.length; i++) {
  print(list[i]);
}

Tags:

Dart Example