A while loop might not ever run. : while « Statements « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Statements » while 
5.1.2.A while loop might not ever run.
int x = 8;
while (x > 8) {
  System.out.println("in the loop");
  x = 10;
}

If the boolean_condition is false when the loop is first encountered, 
then the body of the loop will never be executed. 


public class MainClass {
  public static void main(String[] argv) {
    while (1== 2) {
      System.out.println("here");
    }

  }
}
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
	Unreachable code

	at MainClass.main(MainClass.java:3)
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.