Search⌘ K
AI Features

Solution: Printing a Triangle

Understand how to create a printed triangle shape in Ruby by using loops and string operations. This lesson guides you through incrementing counters and dynamically building the output for each line.

Courtney’s version

Ruby 3.1.2
count = 0
8.times do
count = count + 1
hashes = "#" * count
puts hashes
end

Explanation

  • Line 1: A variable count is created and initialized with the value zero.

  • Line 2: The do ...