DEV Community

Cover image for While Loop in Dart
Jay Tillu
Jay Tillu

Posted on • Edited on

2 2

While Loop in Dart

  • While loop is a type of indefinite loop.

  • The while loop executes the block of code until the condition is true.

  • We mostly use while loop when we don’t know how many times the loop will actually execute at runtime.

  • In simple terms when iterations of a loop are known then we mainly use for loop and when iterations are unknown then we use while loop.

Syntax


while (condition) {
  //Statements to be executed if the condition is true
}
Enter fullscreen mode Exit fullscreen mode

Program


main() {
  int number = 0;

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

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

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

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

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.

Learn more about Dart and Flutter

Follow me for more such content

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay