The answer
Using mathematical bounds inside the for-loop condition is cleaner, much faster, and scales perfectly for any value of N, unlike hardcoded if-statements.
Using mathematical bounds inside the for-loop condition is cleaner, much faster, and scales perfectly for any value of N, unlike hardcoded if-statements.
Map the row number (X) to the star count (Y). Find the difference between Y values (the slope), and use basic algebra (y = mx + b) to find the formula.
The formula is (2 * row) - 1, assuming your row counter starts at 1.
The formula is exactly 2 * row, which prints 2, 4, 6, 8 stars progressively.
Browse all our FAQs or reach out to our support team
Your learning library
Find your next course. Build something great.
Success
Success
Success
Success
Success
Success
Success
Success
Success
Success
Success
Success
Success
Success
Success
Success
Success
Success
Success
Success