dimanche 29 mars 2015

Javascript "For loops" difference between i-5 and i=-5

I want to get multiples of in opposite direction like (eg.95,90,85).I type in this code the browser crashes,'i-5'



for(var i=100;i>=1;i-5)
{
document.write(i+"<br />");
}


But if I type in this code where i=i-5 this works,why is it happening.If i 'i' is variable when I assign 'i=i-5' isn't it assigning values.Like 'i=100' becomes 'i=i-5'



for(var i=100;i>=1;i=i=i-5)
{
document.write(i+"<br />");
}

Aucun commentaire:

Enregistrer un commentaire