Print Out a Triangle
Explore how to print characters in a triangle shape using Ruby by applying loops, variables, and control flow. This lesson helps you understand pattern analysis and reinforces foundational programming concepts by writing a clear, visually structured program.
We'll cover the following...
We'll cover the following...
Printing out characters in shapes is often used as beginner programming exercise, because they are easy to understand and visually interesting programs.
Problem
Write a program to print out hashes in a triangle shape, as shown below:
####################################
Drawn shape of a triangle
Purpose
Develop the ability to analyze patterns
Learn about variables
Learn about looping
Analyze
Row | Number of hashes |
1 | 1 |
2 | 2 |
3 | 3 |
... | ... |
n | n |
Hints
Print out text
We can display text using the
putscommand: However, if we would like to ...