like this
range = (0..10)
how can I get number like this:
0 5 10
plus five every time but less than 10
if range = (0..20) then i should get this:
0 5 10 15 20
Try using .step() to go through at a given step.
.step()
(0..20).step(5) do |n| print n,' ' end
gives...
As mentioned by dominikh, you can add .to_a on the end to get a storable form of the list of numbers: (0..20).step(5).to_a
.to_a
(0..20).step(5).to_a
1.4m articles
1.4m replys
5 comments
57.0k users