Skip to content

Latest commit

 

History

History
66 lines (53 loc) · 980 Bytes

more-loops-worksheet.md

File metadata and controls

66 lines (53 loc) · 980 Bytes

More Loops and Iterators Worksheet

Read the code in each section, then write exactly what the code prints out.

Each problem stands alone. Variables from previous problems do not exist.

Example:

x = 5
y = 6
print(x+y)
# => 11

Problem Set

cars = ["old", "new", "used"]
cars.each do |car|
  puts car
end
fruits = ["banana", "apple", "kiwi"]
fruits.each do |fruit|
  puts "I love " + fruit + "!"
end
values = [8, 5, 3, 10, 14, 2]
values.each do |value|
  puts value
end
total = 0
values = [4, 6, 2, 8, 11]

values.each do |value|
    total = total + value
end

puts total
values = [8, 5, 3, 10, 14, 2]
values.each do |value|
  if value == 10
    puts "Special case!"
  else
    puts "Regular values like #{value}"
  end
end

When you are complete with all of these problems, you can check your answers against the answer key.