Chrome Extension

For loop in Dart

For loop in Dart is used to iterate through dart collections. Different loops examples are explained in this code snippet.
void main() {
  //Simple for loop
  for (var i = 0; i <= 2; i++) {
    print(i);
  }
  
  //Loop through dictionary of maps
  List subjects = [
    {"id": 1, "name": "Math"},
    {"id": 2, "name": "Physics"},
    {"id": 1, "name": "Chemistry"}
  ];
  for (var sub in subjects) {
    print(sub);
  }
  
  //Loop through sets
  Set names = {"Ankit", "John", "Rick"};
  for (var name in names) {
    print(name);
  }
}
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool
Output
0
1
2
{id: 1, name: Math}
{id: 2, name: Physics}
{id: 1, name: Chemistry}
Ankit
John
Rick
Was this helpful?
0 Comments