How to loop through an array with each in Ruby

2 Answers

0 votes
[5, 7, 4, 0, 1].each { |n| 
    puts "n=#{n}" 
}
  
  
  
# run:
#
# n=5
# n=7
# n=4
# n=0
# n=1
#

 



answered Dec 22, 2020 by avibootz
0 votes
arr = ['ruby', 'c++', 'c#', 'java']
 
arr.each do |item|
    puts item
end
  
  
  
# run:
#
# ruby
# c++
# c#
# java
#

 



answered Dec 22, 2020 by avibootz

Related questions

1 answer 210 views
1 answer 193 views
1 answer 205 views
1 answer 220 views
220 views asked Aug 31, 2020 by avibootz
1 answer 191 views
...