Explore 100's Of Free Video Tutorials

Keep Learning, Keep Coding & Keep Sharing

Javascript nested loops

Notes:

JavaScript Nested Loops :


If required we can place one loop inside another loop. This is called as nesting of loops.

Nested for loops:

Case 1: loops with same max value

for(var i=1; i<=n; i++)
{
for(var j=1; j<=n; j++)
{
sequence of statement(s); // n x n times
}
}

Ex:
for(var i=1; i<=2; i++)
{
for(var j=1; j<=2; j++)
{
document.write(“Hello World <br/>”); // 2 x 2 = 4 times
}
}

Interview Questions: