Site icon T4Tutorials.com

4 Level Nested for loop in JAVA SCRIPT??

4 Level Nested for loop in Javascript

4 Level Nested for loop in Javascript is the today topic of discussion in our tutorial. Suppose we are asked to write the four-level nested for loop program that displays the following stars;

*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%

4 Level Nested for loop Program in Javascript

><html> 
<head>
<title>Demonstration of 4 LEVEL NESTED FOR LOOP</title></head>
<body>
<center><h1> NESTED LOOP OF * </h1>
<button onclick="FourLevelNestedLoop()">Please click here</button></center>
</body>
<script language="javascript">
function FourLevelNestedLoop()
{
var i;
var j;
var q;
var k;
for(i=0;i<2;i++)
{
   for(j=0;j<2;j++)
  {
    for(q=0;q<2;q++)
      {
         for(k=0;k<2;k++)
          {
                document.write("*****");
                 document.write("%*%");
           }
      }
    }
}
}


</script>
</html>

Algorithm of 4 Level Nested for loop in Javascript

  1. Start
  2. Add<html>tag
  3. Add <head> tag
  4. Add<title> tags in between <head> tags
  5. Write the name of the title
  6. Close<head> tag
  7. Start <body>
  8. Give heading in <h1> tags
  9. Make a button
  10. End< body> tag
  11. Start <script> tag
  12. Make a function that calls on the button
  13. Declare variables in function as i,j,q,k
  14. Set Four loops to make it 4 levels nested for loop
  15. Place every loop in the body of the first loop
  16. Give command of printing *****and%*% according to conditions of the loop
  17. End </script>
  18. End </html>

Output

*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%*****%*%

 

Exit mobile version