In dart there are total 5 types of Loops.
For Loop
For....in Loop
For Each Loop
While Loop
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++;
}
}