Java labeled while loop. : While « Language Basics « Java






Java labeled while loop.

Java labeled while loop.
//: c03:LabeledWhile.java
// Java's "labeled while" loop.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.


public class LabeledWhile {

  public static void main(String[] args) {

    int i = 0;

    outer:

    while(true) {

      System.out.println("Outer while loop");

      while(true) {

        i++;

        System.out.println("i = " + i);

        if(i == 1) {

          System.out.println("continue");

          continue;

        }

        if(i == 3) {

          System.out.println("continue outer");

          continue outer;

        }

        if(i == 5) {

          System.out.println("break");

          break;

        }

        if(i == 7) {

          System.out.println("break outer");

          break outer;

        }

      }

    }

  }
} ///:~



           
       








Related examples in the same category

1.while Demowhile Demo
2.Do While DemoDo While Demo
3.Demonstrates the while loop.Demonstrates the while loop.
4.Do WhileDo While
5.uses a do-while loop to get this input from the user