LJZN

每天更新Rails练习项目到Github~

» Home
» Category
» About Me
» Github

笨方法学Ruby第三十三天

29 Jun 2016 » LRTHW
i = 0
numbers = []

while i < 6
	puts "At the top i is #{i}"
	numbers.push(i)

	i += 1
	puts "Numbers now: ", numbers
	puts "At the bottom i is #{i}"
end

puts "The numbers: "

# remember you can write this 2 other ways?
numbers.each {|num| puts num }
def zero_to_n(n)

	@numbers = []

	for i in (0...n)
		puts "At the top i is #{i}"
		@numbers.push(i)

		puts "Numbers now: ", @numbers
		puts "At the bottom i is #{i}"
	end

end

puts "Please input a number:"
n = $stdin.gets.chomp.to_i

zero_to_n(n)

puts "The numbers: "

# remember you can write this 2 other ways?
@numbers.each {|num| puts num }

Related Posts