I'm new to programming and it's a Noob question, but I couldn't find any thread that really explain each part to the bottom. I know how to create for loops, but some basic parts aren't clear to me. For example, What makestotal += v[i];
do the next action 10+20+30+40+50 =150
What I mean that if I declared total = 0;
why each value doesn't erase the previous value? e.g: loop run, first value is 10, then 20 run over 10, then 30 run over 20... instead it's keeping the numbers and adding them 10+20...and calculate.
And why I don't need to write var total = 0 ?
var v = [10,20,30,40,50];
var items = v.length;
total = 0;
for (var i = 0; i <items; i++){
total += v[i];
}
var mean = total / items;
alert(mean);