For Loop Variations

The three sections of the for can be used for any purpose. Parts of the for loop can be empty.

 
public class Main {
  public static void main(String args[]) {
    int i = 0;
    boolean done = false;
    for (; !done;) {
      System.out.println("i is " + i);
      if (i == 10)
        done = true;
      i++;

    }
  }
}

The output:


i is 0
i is 1
i is 2
i is 3
i is 4
i is 5
i is 6
i is 7
i is 8
i is 9
i is 10
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.