Dart Loops : While Loop

Dart Loops : While 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 " While Loop " .

  • The while loop is used when the number of execution of a block of code is not known.

  • It will execute as long as the condition is true. It initially checks the given condition then executes the statements that are inside the while loop.

  • In short , The body of the loop will run until and unless the condition is true.

  • The while loop is mostly used to create an infinite loop.

    Syntax:

      while(condition){  
    
             //statement(s);  
    
            // Increment (++) or Decrement (--) Operation;  
    
      }
    
void main() {

    // WHILE Loop

    var  i = 1;
    while (i <= 10) {

        if (i % 2 == 0) {
            print(i);
        }

        i++;
    }
}