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.
- Write that block of the code number of times.
- 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:
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.
This series of posts document a high-level process to use when planning a modern web application, from project organization, collaboration considerations and tooling choices during development, all the way through deployment and performance strategies.