Decision Control Instruction:- After executing some continuously statement , take some decision and then execute a different line(statement).It is also known as selection control and it can be implemented by 3 ways.
- if
- if else
- ?: ternary(conditional) operator
1)if:- to execute a different statement without continuously and to skip a statement if keyword is used.
syntax:
if(condition)
{
//body write statement here
}
example:
syntax:
if(condition)
{
//body write statement here
}
example:
2)if-else:- if condition is correct then if block run else,else block is run.
use of if-else inside if then it become nested if -else.
syntax:
if(condition)
{
//statement;
}
else
{
-----;
}
example:
use of if-else inside if then it become nested if -else.
syntax:
if(condition)
{
//statement;
}
else
{
-----;
}
example:
3)?: (ternary operator):- it is the only one operator in c which required 3 operand to perform their operation.
syntax:- condition?if body statement:else body statement
example:
inside ternary we can also assign a value to a new variable:
example:
x=a>b ? a:b; any one is assign into x from a and b
Comments
Post a Comment