Star Pattern Coding Guide

Jul 9, 2025

Overview

This lecture covers the logic and code structure for creating various star patterns in programming, including square and triangular patterns using nested loops.

Square Pattern

  • The square pattern has an equal number of rows and columns (n x n).
  • Use an outer loop for each row and an inner loop for each column.
  • Print a star (*) in each inner loop iteration, using a space for separation.
  • After finishing each row, print a newline to move to the next row.*

Inverted Mirrored Triangle Pattern

  • The inverted mirrored triangle involves both spaces and stars to create the pattern.
  • The outer loop iterates over each row as before.
  • The first inner loop prints increasing empty spaces on the left; spaces equal to the row index plus one.
  • The second inner loop prints decreasing numbers of stars from n down to 1 as the row index increases.
  • After printing spaces and stars for a row, move to the next line.

Key Terms & Definitions

  • Nested Loop — a loop within another loop, commonly used for grid and pattern generation.
  • Row (r) — represents the horizontal component in the pattern grid.
  • Column (c) — represents the vertical component in the pattern grid.
  • Mirrored Triangle — a triangle pattern that appears to be reflected along a vertical axis.

Action Items / Next Steps

  • Try coding both patterns yourself using nested loops.
  • Subscribe for the next part covering hollow mirrored triangles and hollow squares with diagonals.