Decision-making Statements in java 7

In this section, we will discuss about Decision-making Statements in java 7. This is one type of control flow statement.

Decision-making Statements in java 7

In this section, we will discuss about Decision-making Statements in java 7. This is one type of control flow statement.

Decision-making Statements in java 7

Decision-making Statements in java 7

In this section, we will discuss about Decision-making Statements in java 7. This is one type of control flow statement.

Decision-making Statements :

This kind of control statements is used where you need to take any decision under certain conditions. We write some statements under that condition. Following are the statements which comes under Decision making-

  • If statement
  • switch statement
  • conditional operator statement.

If Statement :

If statement is one of the basic control flow statements. It checks the condition written in if and if condition is satisfied then it executes the block of statements. Otherwise it jumps out of the block. You can also write else part of if by using keyword else.

Syntax :

if(condition)
{.............
statements...
}
else{
.......... statements
}

You can also use multiple if Statement that means you can use nested if-else statements.

Switch Statement :

Switch statement is another decision-making statement used to control the flow of program. Like if-else statements, switch statement holds many conditions to execute. It contains many cases and execute one of them according to the tested variable.

Syntax :

switch(expression){
case value1 : statements.....
                       break;

case value2 : statements.....
                       break;
.
.
.
case value n : statements.....
                       break;
default : statements....
              break;
}

Conditional Operator Statement :

Conditional operator is also known as ternary operator. It checks the condition if true then expression first executes otherwise the second expression executes.
It uses 2 operators (? and :) and 3 operands.

Syntax :

condition ? expression1 : expression2