Refactoring For Loop so it's on only 1 line?


#1



After completing the Ruby Zen chapter I revisted this and am wondering if there is a way to refactor a for loop so that it's on one line? I've tried...

for num in 1...10 { puts num }

but it doesn't seem to work.


https://www.codecademy.com/courses/ruby-beginner-en-XYcN1/1/1?curriculum_id=5059f8619189a5000201fbcb


Replace this line with your code.


#2

Think I figured it out. If anyone knows, please confirm if this is the best way.

for num in 15..20 do print "#{num}, " end


#3

Here's something to play around with:

(15..20).each { |x| puts "#{x}" }