Back to Patterns
Diagonal Pattern
Pattern Result
*********
Code Implementation
Explanation
The Diagonal Pattern creates a shape that forms a diagonal line from the top-left to the bottom-right using asterisks. The pattern places stars only at positions where the row index equals the column index (the main diagonal). All other positions contain spaces. This creates a straight diagonal line across the pattern. The outer loop iterates through each row, and the inner loop iterates through each column, placing a star only at the position where j equals i.