Nested for Loop in JavaScript

Free Web development courses with real-time projects Start Now!!

Program 1

"use strict"
const ps=require("prompt-sync")
const prompt=ps({sigint:true})
let n=parseInt(prompt("Enter the limit"))
let i,j

for(i=n;i>=1;i--)
{
    let x=' '                       
    for(j=1;j<=i;j++)              // x=x+'*' , x=x+j  , x=x+i
    {
        x=x+'*'              
    }
    console.log(x)                      
}


/* 
   n=5
   
   *****
   ****
   ***
   **
   *

 */













// for(i=1;i<=3;i++)   //outer
// {
//     for(j=1;j<=3;j++)  //inner
//    { 
//     console.log(i + "   " +j )
//    }
//    console.log("\n") 
// }

 

Did we exceed your expectations?
If Yes, share your valuable feedback on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *