Java - Compare while loop and for loop

Description

Compare while loop and for loop

Demo

public class Whilestatement {

  public static void main(String[] args) {


    int countnum = 2;
    while (countnum < 20) {
      System.out.println("Count is: " + countnum);
      countnum = countnum + 1;/* w  w w.j  a v  a 2  s. c  o  m*/
    }

    for (int x = 2; (x < 20); x = x + 1) {
      System.out.println("x=" + x);
    }

  }
}

Related Topic