learn_ruby_ch3_pt4 Flashcards
1
Q
loop statement (get string)
A
loop do print "Type something: " line = gets break if line =~ /q|Q/ puts line end
2
Q
for loop print 1 through 5
A
for i in 1..5 do
print i, “ “
end
“do” is optional
3
Q
times loop to print 0 through 9
A
10.times { |i | print i, “ “ } # => 0 1 2 3 4 5 6 7 8 9
4
Q
upto loop (times table for 2)
A
1.upto(12) { |i| print “2 × “ + i.to_s + “ = “, i * 2, “\n”}
5
Q
downto loop (5 4 3 2 1)
A
5.downto(1) { |i| print i, “ “ }