JavaScript for loop Statement Example

Updated on     Kisan Patel

Loops is used to execute a block of statement a specified number of time or till a specified condition is true.

The for loop accepts three parameters; the initial value to start, condition till the loop should execute and increment the value.

Syntax

for (initial condition; terminating condition; stepping condition)

Here is a JavaScript which makes use of for loop

<table border="1">
 <th>Number</th><th>Square</th>

 <script type="text/javascript">
 for (i = 1; i <= 10; i++) {
      document.write("<tr><td>" + i + "</td><td>" + (i * i) + "</td></tr>");
 }
 </script>

</table>

See the Pen NqmaKz by Kisan (@pka246) on CodePen.


JavaScript

Leave a Reply