Conditionals in c language

Started by jayanthi mandhalapu, Jul 29, 2009, 04:37 PM

Previous topic - Next topic

jayanthi mandhalapu

Conditionals are used within the if and while constructs:

    if (conditional_1)
    {
   ...block of statements executed if conditional_1 is true...
    }
    else if (conditional_2)
    {
   ...block of statements executed if conditional_2 is true...
    }
    else
    {
   ...block of statements executed otherwise...
    }

and any variant that derives from it, either by omitting branches or by including nested conditionals.

Conditionals are logical operations involving comparison of quantities (of the same type) using the conditional operators:

   <      smaller than
   <=      smaller than or equal to
   ==      equal to
   !=      not equal to
   >=      greater than or equal to
   >      greater than

and the boolean operators

   &&       and
   ||      or
   !      not

Another conditional use is in the switch construct:

    switch (expression)
    {
   case const_expression_1:
   {
       ...block of statements...
            break;
   }
   case const_expression_2:
   {
       ...block of statements...
            break;
   }
   default:
   {
       ...block of statements..
   }
    }

The appropriate block of statements is executed according to the value of the expression, compared with the constant expressions in the case statement. The break statements insure that the statements in the cases following the chosen one will not be executed. If you would want to execute these statements, then you would leave out the break statements. This construct is particularly useful in handling input variables.


Be Happy And Always Remain So