MY mENU


Wednesday, 15 February 2012

If Statement in C


if statements:
If statement is a conditional branching statement. In conditional branching statement a condition is evaluated, if it is evaluate true a group of statement is executed. The simple format of an if statement is as follows:
if (expression) 
        statement;
  If the expression is evaluated and found to be true, the single statement following the "if" is executed. If false, the following statement is skipped. Here a compound statement composed of several statements bounded by braces can replace the single statement.

if else statement:   This feature permits the programmer to write a single comparison, and then execute one of the two statements depending upon whether the test expression is true or false. The general form of the if-else statement is


if(expression)
          statement1
else
          statement2

                    Here also expression in parentheses must evaluate to (a boolean) true or false.
You can set up an if-else statement to test for multiple conditions. if-else construct, the  if, else if, else. This construct is useful where two or more alternatives are available for selection.


The syntax is
if(condition)
          statement 1;
else if (condition)
          statement 2;
          .....................
          .....................
else if(condition)
         statement n-1;
else
          statemens n ;


No comments:

Post a Comment