Mega Code Archive

 
Categories / Ruby / Array
 

Each with block which has if statement

[1,2,3].each {|i| puts i} # 1 # 2 # 3 [1,2,3].each do |i|   if i % 2 == 0     puts "#{i} is even."   else     puts "#{i} is odd."   end end # 1 is odd. # 2 is even. # 3 is odd.