C++ The if statement:
The if statement is implemented in two forms
1. simple of statement
2. if else statement
Control Statements
In c programming, statements are executed sequentially or step by step in the order in which they are write in the program. Sometimes i want executes some parts of program on the basis of conditions. Also some times many situations arise where we want to use any statement or some statements several times.in all these conditions the control statements are use
Selection Statements |
Iterative Statements |
Jump Statements |
if-else |
while statements |
break |
Switch |
do-while statement |
continue |
|
for statement |
goto |
A compound statement is a block or group of statements enclosed within pair of curly braces {}. So the statements inside a block are execute sequentially
Here is general form of block
{
statement1;
statement2;
statement3;
……….
……….
……….
}
|
if-else
It is bi-directional selection control statement which used to take one action from two possible actions.so here is syntax of an if else statement
(Expression)
{
statement1;
statement2;
………
}
{
statement3;
statement4;
……….
}
|
in above example this expression inside the parenthesis is evaluated if value inside the parenthesis is true (non-zero value), then statements of inside if block executed and if expression is false(zero) then statements of else block executed.
<iostream>
main()
{
a=10,b=6;
(a>b)
{
std::cout<<"Bigger number = "<< a;
}
{
std::cout<<"Bigger number =" << b;
}
0;
}
|