Java programming language provides following types of decision making statements.
|
Sr.No. |
Statement & Description |
|
1 |
An if statement consists of a boolean expression followed by one or more statements. if(condition) { // Statements will execute if the Boolean expression is true } |
|
2 |
An if statement can be followed by an optional else statement, which executes when the boolean expression is false. if(condition) { // Executes when the Boolean expression is true }else { // Executes when the Boolean expression is false } |
|
3 |
You can use one if or else if statement inside another if or else ifstatement(s). if(condition) { // Executes when the Boolean expression 1 is true if(condition 2) { // Executes when the Boolean expression 2 is true } } |
|
4 |
if-else-if Ladder A common programming construct that is based upon a sequence of nested ifs is the if-else if..else ladder. It looks like this: if(condition) statement; else if(condition) statement; else if(condition) statement; . . . else statement; |
|
5 |
A switch statement allows a variable to be tested for equality against a list of values. switch(expression) { case value : // Statements break; // optional
case value : // Statements break; // optional
// You can have any number of case statements. default : // Optional // Statements } |