Skip to Content
Looping in Reverse

What if we want the for loop to log 3, 2, 1, and then 0? With simple modifications to the expressions, we can make our loop run backward!

To run a backward for loop, we must:

  • Set the iterator variable to the highest desired value in the initialization expression.
  • Set the stopping condition for when the iterator variable is less than the desired amount.
  • The iterator should decrease in intervals after each iteration.



Make a for loop that loops backwards printing 3 to 0 to the console. Use the >= comparison operator in your stopping condition and the -- operator in your iteration statement.

Folder Icon

Take this course for free

Already have an account?