Back to Patterns
Checkerboard Pattern
Pattern Result
* * * * ** * * ** * * * ** * * ** * * * *
Code Implementation
Explanation
The Checkerboard Pattern creates a grid where asterisks and spaces alternate in both rows and columns, resembling a checkerboard or chess board. The algorithm determines the starting character for each row based on the row number: even-numbered rows start with an asterisk, and odd-numbered rows start with a space. Within each row, it alternates between the starting character and its opposite. This creates a pattern where no two asterisks are adjacent to each other, forming the classic checkerboard pattern. The outer loop iterates through each row, and the inner loop handles the alternating characters within each row.