Using Ruby, how can I iterate over a for loop n.times

3.times do
   # do work here
end 

check http://www.tutorialspoint.com/ruby/ruby_loops.htm


If you need an index:

5.times do |i|
  print i, " "
end

Returns:

0 1 2 3 4

Reference: https://apidock.com/ruby/Integer/times


It's bad style to use for.

3.times do
  site.posts.each do |video|
    video.some_parameter
  end
end

or if video.some_parameter is one line,

3.times do
  site.posts.each { |video| video.some_parameter }
end

see: https://github.com/bbatsov/ruby-style-guide#source-code-layout