Why shouldn't I use i and j for patterns?
Variables like 'i' and 'j' carry no semantic meaning. Using 'row' and 'space' explicitly documents the loop's geometric purpose.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Optimizing Pattern Code Readability
Because patterns naturally require dense math and nested loops. If you don't write it cleanly, the code becomes impossible to debug or explain to an interviewer.
It means taking a confusing mathematical formula (like 2*row - 1), calculating it, and storing it in a descriptive variable (like maxStars) before the loop starts.
Yes, especially for composite patterns. Creating functions like printStars(int amount) drastically reduces code duplication and makes the main loop highly readable.
Still have questions?
Browse all our FAQs or reach out to our support team
