4 Level Nested Do while Loop in Javascript
4 Level Nested Do while Loop in Javascript
This program is in javascript using 4 levels nested do while loop to solve a program. It contains 4 loops one inside another and the most inner loop has code to print.
A nested loop is a loop within a loop, an inner loop within the body of an outer one. The first pass of the outer loop triggers the inner loop, which executes to the completion. Then the second pass of the outer loop triggers the inner loop again. This repeats until the outer loop finishes its process. If there is a break within either the inner or outer loop it would interrupt this process.
Do while loop executes the statement first and then checks the condition after executing it, which means it will print at least 1 time even if the condition is false.
Flowchart of 4 Level Nested Do while Loop in Javascript
Algorithm of 4 Level Nested Do while Loop in Javascript
The algorithm is a step by step procedure to solve a procedure.
- Start
- Declare Variables
- start outer loop
- start inner loops nested within
- print output ” **”
- increment the variable in every loop.
- Stop
Pseudo Code of 4 Level Nested Do while Loop in Javascript
- tag <script>
- Declare & initialize var i
- Declare & initialize var j
- Declare & initialize var k
- Declare & initialize var l
- go to inner loop print ” **”
- print “\n”
- increment l++;
- check l<2
- print ” **”
- print “\n”
- l++
- check condition false.
- out of loop
- k++;
- check k<2;
- print ” **”
- print “\n”
- k++;
- condition k<2 false
- out of loop
- j++;
- check j<2 true
- print ” **”
- print “\n”
- j++
- condition j<2 false
- out of loop
- i++
- condition i++ true
- print ” **”
- print “\n”
- i++
- condition i<2 false
- out of loop
Program of 4 Level Nested Do while Loop in Javascript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | <script> var i =0; var j =0; var k=0; var l=0; do{ do{ do{ do{ document.write(" **"); document.write("\n"); l++; }while(l<2) k++; }while(k<2) j++; }while(j<2) i++; }while(i<2) </script> |
Output
** ** ** ** **
Topic Covered
4 Level Nested Do while Loop in Javascript.