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,


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.

Do Subscribe with us for more Articles / Tutorials like this,