how to create loop in javascript

index.tsx
// There are multiple ways to create loops in JavaScript such as for loop, while loop, and do-while loop.

// For Loop
for (let i = 0; i < 5; i++) {
    console.log(i);
}

// While Loop
let j = 0;
while (j < 5) {
    console.log(j);
    j++;
}

// Do-While Loop
let k = 0;
do {
    console.log(k);
    k++;
} while (k < 5);
324 chars
21 lines

related categories

gistlibby LogSnag