Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training

The else Keyword

The else is the one more keyword of Java. It is used to specify a statement or block of statements that are executed when the condition for testing specified by the if keyword evaluate to false.

Ads

The else Keyword 

     

The else is the one more keyword of Java. It is used to specify a statement or block of statements that are executed when the condition for testing specified by the if keyword evaluate to false. When the if condition evaluates to false, the code after the else keyword is executed. It is an optional part of a branching statement that starts the 'false' statement block. else  is a java keyword that may not be used as identifiers i.e. you cannot declare a variable or class with this name in your Java program.

The following shows the format of the else selection Construct syntax. 

if (<condition>)

{

 <statements1>

<statements2>

}

 else

{

 <else statements1>

<else statements2>

}

 

When a if selection is encountered during the program's execution, the condition specified by the <condition> is evaluated. Once the condition is met, the statement specified in the if block are executed; then after, the program flow jumps to the end of the if selection. If the condition was not met, then the program flow jumps to the else block, at which point, the statements in the <elsestatements> element are executed.

For instance,

class ElseDemo{
  public static void main(String[] args){ 

  if (x<1){
   System.out.println("smaller than 1");
 }
   else{
   System.out.println("greater than 1");
  }

   }

}

 The else keyword can also be used with multiple if conditions. For example: 

if (<condition1>){

 <statements>

}

else if (<condition2>){

 <statementsX>

}

else{

 <else statements>

Advertisements

Share on Google+Share on Google+

The else Keyword

Posted on: April 3, 2006 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: The else Keyword  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads