learn_ruby_ch3_pt4 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

loop statement (get string)

A
loop do
  print "Type something: "
  line = gets
  break if line =~ /q|Q/
  puts line
end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

for loop print 1 through 5

A

for i in 1..5 do
print i, “ “
end

“do” is optional

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

upto loop (times table for 2)

A

1.upto(12) { |i| print “2 × “ + i.to_s + “ = “, i * 2, “\n”}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

downto loop (5 4 3 2 1)

A

5.downto(1) { |i| print i, “ “ }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly