I'm just starting to learn loops, and in a for loop, if I'm looping through an array, in the second condition, I state that i < arrayName.length. I don't understand the logic here, surely it should be i = arrayName.length; Why does the length have to be < (less than) when you're looping through the entire array?
example:
var myArray = ['cats', 'dogs', 'monster munch'];
for (i = 0; i < myArray.length; i++) {
console.log([i]);
}
Any explanation would be really useful and I'm guessing this is the same with other javascript loop structures?
Emily.
foris the condition which, if true, allows the loop to run through one more time.var i = 0; while(i<myArray.length){ console.log(i); i++; }. And please declare your variablei, or it will end up in the global scope.