Syntax
Ruby Loop N Times Syntax
In Ruby, loop n times: repeats a block N times — 3.times { |i| puts i }
Quick Answer
- Syntax
3.times { |i| puts i }
RubySyntax
Loop N Times
Code example
3.times { |i| puts i }
Repeats a block N times.
How to loop n times in Ruby
- Open your Ruby file or editor.
- Copy the example, then replace its sample names and values for your code.
Ruby Loop N Times Syntax
Use 3.times { |i| puts i }.
Related Syntax References
Frequently asked questions
What is the Ruby syntax for loop n times?
Use this pattern: 3.times { |i| puts i }
Can I copy this Ruby code example?
Yes. Use Copy code and adapt the example to your program.
Is this Ruby syntax different on Mac or Windows?
No. The language syntax is the same across operating systems.
Official source · How we verify