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.

  1. Start
  2. Declare Variables
  3. start outer loop
  4. start inner loops nested within
  5. print output ” **”
  6. increment the variable in every loop.
  7. Stop

Pseudo Code of 4 Level Nested Do while Loop in Javascript

  1. tag <script>
  2. Declare & initialize var i
  3. Declare & initialize var j
  4. Declare & initialize var k
  5. Declare & initialize var l
  6. go to inner loop print ” **”
  7. print “\n”
  8. increment l++;
  9. check l<2
  10. print ” **”
  11. print “\n”
  12. l++
  13. check condition false.
  14. out of loop
  15. k++;
  16. check k<2;
  17. print ” **”
  18. print “\n”
  19. k++;
  20. condition k<2 false
  21. out of loop
  22. j++;
  23. check j<2 true
  24. print ” **”
  25. print “\n”
  26. j++
  27. condition j<2 false
  28. out of loop
  29. i++
  30. condition i++ true
  31. print ” **”
  32. print “\n”
  33. i++
  34. condition i<2 false
  35. out of loop

Program of 4 Level Nested Do while Loop in Javascript

Output

**   **  **  **  **

Topic Covered

4 Level Nested Do while Loop in Javascript.

Latest posts by Prof. Fazal Rehman Shamil (see all)

Buy advertisement space on T4Tutorials

For more details email [email protected]