How to use nested while loop in JavaScript?

The purpose of a while loop is to execute a statement or code block repeatedly as long as an expression is true. Once the expression becomes false, the loop terminates.


You can try to run the following code to learn how to use nested while loop

Live Demo

         var height = 2;
         var width = 8;

         var col = 0;
         var row = 0;
         document.write("Starting Loop<br> ");

         while (row < height) {
            col = 0;

            while(col < width) {
         document.write("Loop stopped!");

Swarali Sree
Swarali Sree

I love thought experiments.

Updated on: 08-Jan-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started