Ruby for Instance / Each

# Define an array of numbers
numbers = [1, 2, 3, 4, 5]

# Use the each loop to iterate over the numbers array
numbers.each do |number|
  # Print each number to the console
  puts number
end

# Define a hash of colors and their hexadecimal values
colors = {
  red: "#ff0000",
  green: "#00ff00",
  blue: "#0000ff"
}

# Use the each loop to iterate over the colors hash
colors.each do |name, value|
  # Print each color name and value to the console
  puts "#{name}: #{value}"
end

Try on playground

Next: range

made with by dfxe / source / license