Decision statements
1)Ifelse statement
- It is used to check some condition.
Syntax:-
if(condition)
{
if block
}
else
{
else block
}
- If condition is true then if block executed and condition is false then else block executed.
2)Nested if else statement.
- It is used to check multiple condition.
Syntax:-
if(con. 1)
{
if(con 2)
{
if block
}
else
{
else block
}
}
else
{
if(con 3)
{
if block
}
else
{
else block
}
}
- If con 1 is true then it check for con. 2 if it is true then if block executed otherwise else block executed.
- And if con. 1 is false then it check for con. 3 if it is true then if block executed otherwise else block executed.
3)Else if ladder
- It is also used for check multiple condition.
- If con. 1 is true then block 1 executed.if it is false then it will check for con. 2 if con 2 is true then block exceuted.
- If it is false then it will check for con. 3 if it is true then block 3 executed.and if it false then else block executed.
- It is another multiple choice statement.
Syntax:-
Switch(variable)
{
case 1:
block1;
break;
case 2:
block 2;
break;
default:
break;
}
No comments:
Post a Comment