Decision Making Statements :
Java programming language provides following types of decision making statements.
(i) if statement – 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
}
Reference video: java if statement
(ii) if…else statement – 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
}
Reference video: java if else statement
(iii) nested if statement – You can use one if or else if statement inside another if or else if statement(s).
if(condition) {
// Executes when the Boolean expression 1 is true
if(condition 2) {
// Executes when the Boolean expression 2 is true
}
}
Reference video: java nested if statement
(iv) 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;
Reference video: java if-else-if Ladder
(v) switch statement – 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
}
Reference video: java switch statement
Jump Statements :
When transferring programme control to the individual statements, jump statements are utilised. Jump statements, in other words, shift the program’s execution control to another section. Break and continue are the two different forms of jump statements in Java.
(i) break statement – Terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch.
break;
(ii) continue statement – Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.
continue;