JavaScript For Loop Example

JavaScript for loop check condition and executes block of code for a specific number of times, until specified condition argument become false.

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>JavaScript for loop</title>
</head>
<body>
<pre>  <!-- Use pre element for work document.writeln() method -->
<script>
  for( var num = 1; num <= 10; num++ ){
      document.writeln(num + ": iteration");
  }
  document.writeln("End of for loop");
</script>
</pre>
</body>
</html>

Run it...   »

Example Result