Loops are very important part of any programming language they give us ability to repeat something upon our given condition. Let’s say if we are writing a table from 1 to 10 and on each line we have to multiply 2 with 1 , 2 , 3 , 4 upto 10 instead of doing that each line we will do this in loop. Which will reduce our efforts. The syntax of loop in javaScript is like
[code]
counter;
while(counter <= 10) {
document.write(counter+'<br>’);
counter++;
}
[/code]
The above line is while loop which will repeat the loop to print the number on screen upto 10 starts from 0. There are different loops in javaScript you can read about them.
Flow Chart for Loop.
Infinite Loop
Infinite loop is when your loop do not have any condition which turn it off and that continuously repeat itself. Or infinite loop can begin when the given condition to stop loop always gets true and loops always works. Suppse if you are running a counter and by mistake in condition you have written while($counter > 1) which means while counter is greater than 1 on each run counter will remain greater than 1 and this loop will never ends. This will reduce the speed of your server and will damage your website on user’s computer also this can hang up the user’s computer. Always be careful using loops in javaScirpt otherwise users will stop visiting your site cause they will think our website make their computer hang and make them restart it.