Alexandre Tavares Alexandre Tavares - 1 year ago 68
Ruby Question

Print numbers in a range

I am trying to print all numbers between 1 and 50, using the following code:

[1..50].each{|n| puts n}


but the console print

[1..50]


I want to print something like this
1
2
3
4
...
50

Answer Source

Try the following code:

(1..50).each { |n| puts n }

The problem is that you're using [] delimiter instead of () one.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download