JavaScript For Loop

For loop provides a concise way of writing the loop structure and it’s most compact form of looping.

The for loop requires following three parts:

  • Initializer: Initialize our counter variable to start with
  • Condition: specify a condition that must evaluate to true for next iteration, otherwise the control will come out of the loop
  • Iteration: increase or decrease counter

Flow Chart
for loop
Example:

<html>
<body>
<script>
document.write(“Loop Starting<br>”);
for(count = 0; count < 10; count++){
document.write(“Current Count : ” + count );
document.write(“<br>”);
}
document.write(“Loop Stopped”);
</script>
</body>
</html>


Output:
output

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.