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

Big O Forum

View Course

946 points
51ba70f8631fe9fdba000b9e_722797588
Submitted by
siaw23™
over 4 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

permalink

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
86f4529b25c6db567a8e900f84fdbebf?s=140&d=retro
Submitted by
mareau
over 4 years ago

1 Comment

51ba70f8631fe9fdba000b9e_722797588 siaw23™ over 4 years ago

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