Tuesday, May 12, 2009

If Statements

If statements
The if statements is having two type of statements
1. simple if statements
2. if-else statements
3. nested if-else statements

simple if staments
It is used to control the flow of execution of the statements and also used to test logically to find whether the condition is true false.

Syntax:

if (condition)
{
statements 1;
}
statements 2;

If the conditions is true, then the statements 1 will be executed. The true statements may be a single statements or group of statements. If the condition is false then the statements 1 are not executed but statements 2 will be executed.


Example:

if (a>=10)
{
cout<<”A is greater than or equal to 10”;
}
cout<<”A value is less than 10”;

The above example : the condition is true output will be proved “A is greater than or equal to 10” . If the condition is false output will be proved ”A value is less than 10”.

void main()

{

Int a;

cout<<”Enter the Value of A: “;

cin>> a;

If(a<=10;
{

cout<<”A value is less than or equal to 10 “;

}

cout<<”A value is greater then 10”;

}

If a value is 6


The output will be:


Enter the Value A:


6

A value is less than or equal to 10



If a value is 15


The output will be:


Enter the Value A:

15

A value is greater then 10

No comments:

Post a Comment