foreach dart code example

Example 1: loop in dart

for (int i = 0; i < 3; i++) {
	print(i);
}

Example 2: dart for in loop

var mylist = [6, 7 ,8]; 
for (var e in mylist) { 
	print(e); 				// 6 7 8
} 
for (int i = 0; i < mylist.length; i++) {
	print(e);				// 6 7 8
}
mylist.forEach(e) {
	print(e);				// 6 7 8
}

Example 3: 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));    
}

Tags:

Misc Example