JavaScript while Statement Example

Updated on     Kisan Patel

In javascript, while statements help us in implementing the iterative logic of the program.

The syntax of while is as follows:

Some initial condition
while ( terminating condition )
{
   some statements
   stepping condition
}

The while is implemented by following JavaScript.

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

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

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


JavaScript

Leave a Reply