for loop not running
it says 'the for loop was not used' although it's there. what am i missing?
animals = ["dog", "cat", "horse", "goat"] for i in 0..3 do puts animals[i] end
Chris Shaw26,637 Points
At the moment your
for loop isn't referencing the
animals array but instead you have
0..3, instead this should be referencing
animals so the
for loop can iterate over each value.
One other thing is you're using the variable
i within square brackets which isn't needed as ruby will automatically assign each array value to
i therefore it would make far more sense to call it
animal instead and use that in our
With that said you would end up with something like the following which is what the challenge is expecting.
for animal in animals do puts animal end