Loop-based Pattern Printing

Learn various loop-based star and number patterns with step-by-step logic, diagrams, examples, and live code editors.

1. Right-Angled Triangle

A right-angled triangle prints stars row-wise, increasing with each row.

Right-Angled Triangle
Diagram

Learn more about programming concepts at !Variables, Loops & Conditions

Example: 5 rows


2. Pyramid Pattern

Pyramid pattern prints stars in the shape of a pyramid.

Pyramid Pattern
Diagram

Example: 5 rows


3. Number Pyramid

A pyramid pattern printing numbers increasing from left to right.

Number Pyramid
Diagram

Example: 5 rows


4. Inverted Pyramid

Inverted pyramid prints stars in decreasing order to form an inverted shape.

Inverted Pyramid
Diagram

Example: 5 rows


5. Diamond Star Pattern

Diamond pattern combines pyramid and inverted pyramid.

Diamond Pattern
Diagram

Example: 5 rows top pyramid


6. Number Pyramid

Let's print a centered number pyramid (1, 121, 12321, ...). This pattern helps you practice nested loops and see how numbers and spacing work together to create neat shapes. Change the `rows` variable to try different sizes.

Number Pyramid Diagram
Diagram: Centered Number Pyramid

Example for rows = 5: outputs
1
121
12321
1234321
123454321


7. Floyd’s Triangle

Floyd's Triangle prints numbers in a continuous sequence in triangle shape.

Floyd's Triangle
Diagram

Example: 5 rows


8. Right Pascal’s Triangle

Right Pascal's Triangle is a combination of a normal and inverted right-angled triangle.

Right Pascal's Triangle
Diagram

Example: 5 rows top triangle


9. Pascal’s Triangle

Pascal's Triangle prints numbers where each number is the sum of the two numbers above it.

Pascal's Triangle
Diagram

Example: 5 rows


10. Hollow Diamond Pattern

Hollow Diamond prints a diamond with empty space inside, using stars at borders.

Hollow Diamond
Diagram

Example: 5 rows top pyramid


Enjoyed this article?

Share it with your network!