In this article we will discuss how to use for loop with two variables.

For loop is basic feature we use in programming. In it we use a variable and keep on increasing or decreasing it till a condition is matched.

But many times a scenario comes where we want to increment or decrement two variables instead of one.

For example, I want to do for loop with 2 variable i.e.

  • i that will increment from 0 to 9
  • j that will decrement from 10 to 1

Here condition till which loop will run is (i < 10 && j > 0)

Let’s see how to do that,

For Loop with two variables in C++


For Loop with two variables in Java

Output for the above programs is,


Python Recommendations:

C++ & C++11 Recommendations:

If you didn't find what you were looking, then do suggest us in the comments below. We will be more than happy to add that.

Subscribe with us to join 1500+ Python & C++ developers, to get more Tips &  Tutorials like this.