The For Loop

If we want to print numbers such as 1 through ten. Yes we can type console.log(1) and retype it ten 10 time. However, we wan tto save data and avoid repetion of code.

  1. For(initialize;test; increment/decrement
    decrement) {// code Block//}
  2. Eample standard For Loop
  3. for(var i = 0; i < i; i++ {
    console.log(i);} // this will print the number from 1 thourgh 10.)
  4. We use i, because that is short for index

The While Loop

The loop then performs some action, which affects that condition repeatedly until that condition becomes false.

for (var i =0; i < 11; i++) {
console.log(i);
}

var roopak = ['Roopak', 'kumar', 1990, 'student', true];
for (var i = 0; i < roopak.length; i++) {
console.log(roopak[i]);
}


//While Loop

var i = 0;
while(i < roopak.length) {
console.log(roopak[i]);<br /> i++;
}


click 'Check' to see the answer