Read the code in each section, then write exactly what the code prints out. Use a loop table to help you track each variable for each iteration.
Each problem stands alone. Variables from previous problems do not exist.
Example:
x = 5
y = 6
print(x+y) #=> 11
2.times do
puts "dance"
end
10.times do |i|
puts i
end
3.times do
puts "coding!"
end
puts "fun!"
5.times do |x|
puts "#{x} chicken(s)"
end
10.times do |i|
puts i * i
end
(1..5).each do
puts "hello!"
end
(1..3).each do |i|
puts "#{i} animals(s)"
end
(1..3).each do |i|
puts i * i
end
total = 0
(1..3).each do |i|
total = total + i
end
puts total
(1..10).each do |x|
if x == 5
puts "You got a winner!"
end
end
i = 0
while i < 3
puts “hi”
i = i + 1
end
i = 0
while i < 3
puts “hi”
i = i + 1
end
puts "bye"
i = 0
while i < 3
i += 1
puts i
end
x = 5
i = 0
while i < 3
x = x + 1
i = i + 1
end
puts x
i = 3
while i > 0
puts "ada!"
i = i - 1
end
i = 1
while i
puts "a while"
end
i = 1
while i < 100
puts "o hai"
i = i * 100
end
When you are complete with all of these problems, you can check your answers against the answer key.