Loops repeat a block of code. They are useful when you need to do the same kind of work multiple times.
for (let index = 1; index <= 3; index++) {
console.log(index);
}
let attempts = 0;
while (attempts < 3) {
console.log("Trying again...");
attempts++;
}
const topics = ["loops", "functions", "JSON"];
for (const topic of topics) {
console.log(topic);
}
topics.forEach((topic) => {
console.log(`Review ${topic}`);
});
for when you need an index or exact count
while when the stop condition is the main focus
for...of for readable iteration over arrays