codegurukool.com · Free coding tutorials & online compiler

Home › JavaScript Tutorial › JS loops

JS loops

Repeat code.

for counts, while repeats while true, for...of walks values. Use break and continue to control them.

Example code

<pre id='o'></pre>
<script>
let t='';
for(let i=1;i<=3;i++)t+='for '+i+'\n';
let n=3;while(n>0){t+='while '+n+'\n';n--;}
for(const c of 'JS')t+=c+' ';
o.textContent=t;
</script>

Run this code in the online editor

← JS operatorsJS strings →