Control Statements in Java :
Control statements are those statements that is used to control the flow of the program.
There are basically three types of control statements
1.Selection Statements
2.Iteration Statements/Repetition/Looping Statements
3.Jump Statements
Selection Statements:
Selection statements of java is further divided into types these are:
1.If
2.Else-If statements
3.Switch Statements
If Statements :
If is one way condition statements.Let us consider an example to understand the concept more clear.
Syntax:
if(Test Condition)
{
//Here is the statements that to be executed if condition is true otherwise statements will be executed.
}
Statements-x
we can also use two way decision making statements that is if else.
Syntax:
if(Test Condition)
{
//Here is the statements that to be executed if condition is true otherwise statements will be executed.
}
else
{
//Here is the statements that to be executed if condition is test condition is false otherwise statements will be executed.
}
Else if statements :
If we want check multiple condition than we use Else if statements.
Syntax:
if(Test condition 1)
{
//if test condition is true than this block is executed
}
else if(Test condition 2)
{
//if test condition is true than this block is executed
Control statements are those statements that is used to control the flow of the program.
There are basically three types of control statements
1.Selection Statements
2.Iteration Statements/Repetition/Looping Statements
3.Jump Statements
Selection Statements:
Selection statements of java is further divided into types these are:
1.If
2.Else-If statements
3.Switch Statements
If Statements :
If is one way condition statements.Let us consider an example to understand the concept more clear.
Syntax:
if(Test Condition)
{
//Here is the statements that to be executed if condition is true otherwise statements will be executed.
}
Statements-x
we can also use two way decision making statements that is if else.
Syntax:
if(Test Condition)
{
//Here is the statements that to be executed if condition is true otherwise statements will be executed.
}
else
{
//Here is the statements that to be executed if condition is test condition is false otherwise statements will be executed.
}
Else if statements :
If we want check multiple condition than we use Else if statements.
Syntax:
if(Test condition 1)
{
//if test condition is true than this block is executed
}
else if(Test condition 2)
{
//if test condition is true than this block is executed
}
else if(Test condition 3)
{
//if test condition is true than this block is executed
{
//if test condition is true than this block is executed
}
else if(Test condition 4)
{
//if test condition is true than this block is executed
{
//if test condition is true than this block is executed
}
else
{
//if any condition is not true than this default condition is execeuted.
}
Switch Statements:
0 Comments