DEV Community

Cover image for Do-While Loop in Dart
Jay Tillu😎
Jay Tillu😎

Posted on • Updated on

Do-While Loop in Dart

  • A do-while loop is a type of indefinite loop.

  • do-while loop first executes the statements and then check for the condition. If the condition is true it will keep executing and if the condition is false loop will terminate.

  • So whether the condition is true or false, do while loop’s statements will execute at least once.

Syntax


do {
  Statement(s) to be executed;  
} while (expression);
Enter fullscreen mode Exit fullscreen mode
  • Here also take a look that in for loop or while loop we don’t use semicolon at the end of the loop. But in do while loop semicolon is mandatory after the while statement.

  • Incrementer or decrementer must be placed inside the do’s block, it cannot be placed outside the do’s block.

Program


main() {
  int number = 0;
  do {
    if (number % 2 == 0) {
      print(number);
    }
      number++;
  } while (number < 10);
}

Output
0
2
4
6
8
Enter fullscreen mode Exit fullscreen mode

That’s it for do-while loop guys. Feel free to share with me if I miss something I will love to learn it from you.

Remember no teacher, no book, no video tutorial, or no blog can teach you everything. As one said Learning is Journey and Journey never ends. Just collect some data from here and there, read it, learn it, practice it, and try to apply it. Don’t feel hesitate that you can’t do that or you don’t know this concept or that concept. Remember every programmer was passed from the path on which you are walking right now. Remember Every Master was Once a Beginner. Work hard and Give your best.

Till Then Keep Loving, Keep Coding. And just like always I’ll surely catch you up in the next article.

For More Information Please Visit Following Links

Jai Hind, Vande Mataram 🇮🇳

Wanna get in touch with me? Here are links. I’ll love to become your friend. 😊

Oldest comments (0)