Multiple expressions in for loopsTag(s): Language


Simply use a "," between each expression.

public class MultipleFor{
  public static void main (String [] args){
    for (int i=0, j=0; i < 10; i++, j--) {
      System.out.println ("i = " + i + " j= " + j);
    }
  }

  /*
  output :
  i = 0 j= 0
  i = 1 j= -1
  i = 2 j= -2
  i = 3 j= -3
  i = 4 j= -4
  i = 5 j= -5
  i = 6 j= -6
  i = 7 j= -7
  i = 8 j= -8
  i = 9 j= -9
  */

}

blog comments powered by Disqus