-->
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Saturday, July 15, 2017

If-Else

The if statement is used to test a condition and make desicion depending upon the test condition. The test condition is evaluated and a boolean value is returned: true or false. Depending upon wheteher the condition is true or false a particulae set of statement is executed.

There are many type of if-else statement present in Java:
 i)if statement
ii)if-else statement
iii)Nested if-else statement
iv)if-else-if ladder


if statement
Synatx:
 if(test condition)  
 {  
 //set of statements which is to be executed if the test condition is true  
 }  

If the condition is false then the program continues with the execution of rest of the program without executing the statement(s) written inside if block.

if-else statement
The if-else statement also tests the condition. It executes the if block if condition is true otherwise else block will be executed.
Syntax:
 if(test condition)  
 {  
 //set of statements which is to be executed if the test condition is true  
 }  
 else  
 {  
  //set of statements which is to be executed if the test condition is false  
 }  

Please note that only one of the above blocks will get executed 

Nested if-else statement
Syntax:

 if(test condition 1)  
 {  
 if(test condition 2)  
 {  
 //statement 1  
 }  
 else  
 {  
 //statement 2  
 }  
 }  
 else  
 {  
 //statement 3  
 }
 //statement x  





if-else-if ladder
The if-else-if ladder is used to execute one statement from multiple conditions
Syntax:

 

No comments:

Post a Comment