5.12 why does this works?


odds = [1,3,5,7,9]

munbers.each do |odds*2| 
    print odds

// this is my code --- why does not work?

odds.each do |x|
    if x % 2 != 0 // why do this line is necessary and what it means x%2? it equals to what??
        puts x * 2
 // this a working code found here on the forum why do this works and mine not?


You are trying to iterate over an iterable that does not exist, munbers

Ruby do loop syntax,

object_being_iterated_over = [5,3,2,1]

object_being_iterated_over.each do |empty_var |
    print empty_var //This will print the values inside the, object_being_iterated_over


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.