How to creating a FOR loop and a WHILE loop in JavaScript
Creating a for loop and a while loop in JavaScript using below simple example:
// Example: Printing numbers from 1 to 5 using a for loop
for (let i = 1; i <= 5; i++) {
console.log(i);
}
In this example, the for loop iterates over the values of i
from 1 to 5. It prints the value of i
in each iteration using console.log()
.
While Loop: