Facebook Pixel
How to Print an Inverted Right-Angled Triangle Pattern

Does reversing the loop direction change the execution speed?

The answer

No, traversing from N to 1 takes the exact same amount of hardware cycles as traversing from 1 to N.

More FAQs in How to Print an Inverted Right-Angled Triangle Pattern

If the outer loop runs from 1 to N, the number of stars per row is N - row + 1.

Reversing the outer loop (starting from N and decrementing) is usually much cleaner and easier to read, reducing the chance of off-by-one math errors.

Use the same loop structure, but inside the inner loop, print the variable 'col' (for 1234, 123) or 'row' (for 4444, 333).

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Your learning library

Small steps. Big possibilities.

Find your next course. Build something great.

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.