Control Statement in Java

0
Share

What is Control Statement ?

These statement controls the flow of execution known as Control Statement. In java there are 2 different control statement used such as:-

  • Decission Making Control Statement.
  • Looping Statement.

Decission Making Control Statement.

  • Those control statement makes decision for executing is known as decision making control statement.
  • There are 3 different decision making control statement used like :-
  • If decission making control statement
  • Switch case decision making control statement.
  • Conditional Operator decision making control Statement.

Simple If Statement

Syntax
If(condition)
{
Statement;
}
  • When the keyword ‘If’ will be defined with a true block known as ‘simple if’ .
  • In this case here the if condition is satisfied the true block will be executed & control transfer to the next part of the program, otherwise the true block remain silent & control transfer to the next part of the program.

If …. else Statement

Syntax
if (Condition)
{
Statement..;
}
else
{
Statement ..;
}
  • In if … else statement if both true block & false block are defined known as If… else Statement.
  • In this case either block will be executed, If condition is satisfied the true block will be executed & false block remain silent.
  • Otherwise the true block remain silent & the false block will be executed.
  • After execute either block the control transfer next part of the program.

Nested if …. else Statement

Syntax
if (Condition)
{
 if(Condition)
     {
   Statement;
     }
 else
    {
   Statement;
    }
}
else 
{
  if(Condition)
       {
       Statement;
       }
   else
       {
       Statement;
       }
}
  • In this case if, one if occures another if it is known as nested if statement.
  • In case of Nested if .. else only the structure is different but the process flow exactly same with if… else.

If …. else …if Ladder Case

Syntax
if(Condition)
{
Statement ;
}
else if (Condition)
{
Statement ;
}
else if (Condition)
{
Statement ;
}
.
.
.
.
else
{
Statement;
}
  • In this case ‘If’ the next condition occurs only , when the previous condition false known as if…else…if ladder Statement.
  • In case of ‘else if ‘ ladder , if condition will be satisfied the true block will be executed & control transfer to the next part of the program.
  • Otherwise the true block remain silent &control transfer to the false block to the checking condition & so on.
  • This structure look like a ladder shape that’s why it’s name was if…else…if ladder statement.

Switch Case

Switch (Constant)
{
    Case 1:
    Statement 1 ;
    break;
    Case 2:
    Statement 2;
    break;
    Case 3:
    Statement 3;
    break;
    default
        Statement ;
}
  • Switch case is another decision making control statement in java.
  • In case of switch case the keyword switch contain a single value either character type or integer type & compare it with different case value, where the case value is matched that case will be execute & other remain silent.
  • If no match is found the default statement will be execute at the end of each case and the break keyword is used to exist switch case.
  • Basically making the menu driven application we use switch case statement.

To follow our another article below given links

  • What are the List of CSS3 New Features ?
    CSS3 is the latest version of the normal CSS . CSS3 adds several new styling features and improvements to enhance the web presentation capabilities. Text Effect in...
  • CSS Basic Property
    What is CSS ? CSS stands for Cascading Style Sheets. CSS basically used in designing the web tags & pages. CSS is the most popular used...
  • Java Program to swap two number use 3rd variable
    In this program, you’ll learn to Program to swap 2 number with 3rd variable in Java. After write the code, the final output is displayed on...
  • Java program to multiply two floating point number
    In this program, you’ll learn to Program to multiply two floating point number in Java. After write the code, the final output is displayed on the...
  • Java Program to find the ASCII value of a character
    In this program, you’ll learn to Program to find the ASCII value of a character in Java. After write the code, the final output is displayed...
  • Java Program to calculate quotient & reminder
    In this program, you’ll learn to Given Number is even or odd in Java. After write the code, the final output is displayed on the screen....
%d bloggers like this: