Dart Loops : For ... in Loop

Dart Loops : For ... in Loop

In dart there are total 5 types of Loops.

  1. For Loop

  2. For....in Loop

  3. For Each Loop

  4. While Loop

  5. Do.....While Loop

In this section we will see about Dart " For....in Loop " .

  • The for..in loop is similar to for loop but different in its syntax.

  • It iterates through an object's properties. The Dart for..in loop accepts an expression as iterator and iterates through the elements one at a time in sequence.

  • The variable var holds the values of the iteration. The for…in will execute until elements remain in iterators.

  • 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.

    Dart For In Loop Flow Diagram

  • Syntax

      for (var in expression) {  
           //statement(s)  
      }
    
    // for ..in loop
    List planetList = ["Mercury", "Venus", "Earth", "Mars"];

    for (String planet in planetList) {
        print(planet);
    }
}