For loop question


#1

Why the word "grasshopper "is only written once?Not many many times?


#2

It depends what your code looks like.


This will print out each letter separately. The loop runs once for each letter of the string.

for (let letter of 'grasshopper') {
  print(letter);
}

This will print out 'grasshopper' once (because there is 1 item in the array.)

for (let word of ['grasshopper']) {
  print(word);
}

This will print out 'grasshop' 11 times (once for each letter of 'grasshopper').

for (let letter of 'grasshopper') {
  print('grasshop');
}

–Frankie


#3

ok,thank you so much.