Using while Loops : while « Statements « SCJP






while (boolean_condition){
   repeated_statement_or_block
}


boolean_condition must be an expression that returns a boolean result. 
repeated_statement_or_block is the body of while statement.
repeated_statement_or_block will be executed again and again as long as the boolean_condition is true. 




public class MainClass {
  public static void main(String[] argv) {
    int i = 0;

    while (i < 5) {
      System.out.println(i);
      i++;
    }

  }
}
0
1
2
3
4








5.1.while
5.1.1.Using while Loops
5.1.2.A while loop might not ever run.
5.1.3.Protect while loop controller variable