Nov 12
  • The break and continue statement can be followed by a label.
  • The presence of a label will transfer control to the start of the code identified by the label.
  • The label name can be anything that follows java naming rules.

General use of labelled break is as follows :

outer :

while (<condition>)

{

<statement 1>;

while(<condition>)

{

<statement2>;

if(<condition>)

{

break  outer;

}

}

<statement 3>;

}

General use of labelled continue is as follows :

test:

while (<condition>)

{

<statement 1>;

while(<condition>)

{

<statement2>;

if(<condition>)

{

break  test;

}

}

<statement 3>;

}

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Blogplay
  • LinkedIn
  • MySpace
  • Reddit
  • RSS
  • Twitter

written by Anup

Nov 12

With traditional for loop , we need to know the size of the array for iteration .

But with Enhanced for loop ,array iteration becomes simpler and easier.

Use of  Enhanced for loop :

public class check {

  public static void main(String[] args) {
       int[] numbers = {1,2,3,4};
          System.out.println("Numbers are :");
            for (int num : numbers){
             System.out.println(num);
             }
      }
  }

  • Remember instead of num ,we can use any valid identifier or name.
  • Type of variable used to iterate in Enhanced for loop should match the type of array.
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Blogplay
  • LinkedIn
  • MySpace
  • Reddit
  • RSS
  • Twitter

written by Anup

Aug 03

The statements inside your source files are generally executed from top to bottom, in the order that they appear.

Control flow statements, however, break up the flow of execution by employing decision making, looping, and branching, enabling your program to conditionally execute particular blocks of code.

Statement type

Keyword

Selection if – else ,switch – case
Iteration while ,do – while , for (normal as well as enhanced)
Jump return , (labeled as well as unlabeled form) : break , continue
Exception handling try – catch – finally , throw
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Blogplay
  • LinkedIn
  • MySpace
  • Reddit
  • RSS
  • Twitter

written by Anup