DEV Community

Cover image for Loops in Dart
Jay Tillu😎
Jay Tillu😎

Posted on • Updated on

Loops in Dart

There are many situations occur while coding, when we want to repeat a certain block of code for a number of times. Now there are two ways to do the job.

  1. Write that block of the code number of times.
  2. Use Loops.

Now in the first case, the problem is your code will become too lengthy and boilerplate. And also after a certain time, it will become too hard to maintain that code. And as there is a general rule in programming that “never repeat your code”.

So to rescue you in that situation loops come into the picture. To repeat some statements number of times we use loops.

The statements inside the body of the loop will keep repeating until the condition becomes false.

The repetition of a loop is called Iteration in programming.

  • There are two types of loops are there in programming:
  1. Definite
  2. Indefinite

Definite Loop - The Loop whose number of iterations is fixed, where you know the exact number of iterations before entering the in the loop, then it is called a definite loop. for ex- for loop

Indefinite Loop - The Loop whose number of iterations is not fixed, where you don’t know the exact number of iterations before runtime, then it is called indefinite loop. Ex — while loop & do-while loop

That’s it for loops guys. Again it’s a first introductory article on loops. We will discuss all three loops in upcoming articles.

As usual, if I miss something please feel free to let me know. Till Then Keep Loving Keep Coding. I’ll surely catch you up in the next article.

Jai Hind, Vande Mataram 🇮🇳

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

Top comments (0)