JavaScript Loops: Code Only
1. `for` Loop
for(let i=0;i<3;i++) o1+=`Count: ${i}\n`;Output:
2. `while` Loop
let j=0;while(j<3){o2+=`Count: ${j}\n`;j++;}Output:
3. `do...while` Loop
let k=0;do{o3+=`Count: ${k}\n`;k++;}while(k<3);Output:
4. `for...in` Loop
const o={a:10,b:20};for(const k in o) o4+=`${k}:${o[k]}\n`;Output:
5. `for...of` Loop
const a=["X","Y","Z"];for(const v of a) o5+=`Value: ${v}\n`;Output:
6. `Array.forEach()`
[10,20,30].forEach((n,i)=>o6+=`Idx ${i}: ${n}\n`);Output: