Answers for "ruby fori"

1

for loop ruby

# You can use an each to mimic the functionality of a for loop

(0..5).each do |i|
  puts "Inside loop i = #{i}"
  # put your code for loop here
end

# outputs 
# Inside loop i = 0   
# Inside loop i = 1
# Inside loop i = 2
# Inside loop i = 3
# Inside loop i = 4
# Inside loop i = 5
Posted by: Guest on October-25-2020
0

ruby for

for counter in 1..5
  puts "iteration #{counter}"
end
#=> iteration 1
#=> iteration 2
#=> iteration 3
#=> iteration 4
#=> iteration 5
Posted by: Guest on January-07-2021

Browse Popular Code Answers by Language