what is nested loops ??
A nested loop means placing one loop inside another loop. The outer loop executes first, and for each iteration of the outer loop, the inner loop executes completely.
example -- 1
*
1. **Print a 5 × 5 Star Pattern*
for (let i = 1; i <= 5; i++) {
let row = "";
for (let j = 1; j <= 5; j++) {
row += "* ";
}
console.log(row);
}
**
OUTPUT:
**example -- 2
**for (let i = 5; i >= 1; i--) {
let row = "";
for (let j = 1; j <= i; j++) {
row += "* ";
}
console.log(row);
}
OUTPUT:
- * *
USES OF PATTERN PROGRAMS
Understanding FOR & NESTED Loops
They provide simple examples for learning how loops work, including:
Initialization
Condition
Increment/decrement
Top comments (0)