Solution Review: Print Even/Odd Numbers in Descending Order

This lesson will help print even/odd numbers in descending order using a loop.

We'll cover the following

Solution: Use a while Loop

Use a while loop that does the following in each iteration:

  • checks if the number is divisible by 2 using the modulus operator. If yes, then it prints it as even (and otherwise, it’s odd).
  • it decrements the input value n

It does this until the number n is greater than 0.

Get hands-on with 1400+ tech skills courses.