This forum is now read-only. Please use our new forums at

946 points
Submitted by
almost 6 years ago

what's the relation to var i?

please look at this code:

for(var i = 0; i < 5; i++){
console.log("cat"); }

what has the variable "i" got to do with printing "cat"? where does it tell console.log to print cat 5 times. i get the "for" condition but the relation to print it to the condition is what i don't get. if someone can explain please.

0 votes


I think you are missing how a for loop works.

console.log("cat") is the block of code you want to execute every time the condition i < 5 is true

159 points
Submitted by
almost 6 years ago

1 Comment

51ba70f8631fe9fdba000b9e_722797588 siaw23™ almost 6 years ago

yes i was missing it. now i get it. thank you very much!