Search This Blog

Translate

How does Switch statement differ from Nested if

How does Switch statement differ from Nested if


Switch
Nested if
Switch can test only for equality
Nested if can evaluate any type of
relational or logical expression
Character constants used in switch
statement are automatically converted to integers
No conversion is required
Syntax:
Switch(expression){
Case constant1:
Statement sequence
Break;
Case constant2:
Statement sequence
Break;
.
.
.
Default
Statement sequence
}

if (condition1)
{
     if (condition2)
     {
          True statement  - 2;
     }
     else
    {
           False statement - 2;
    }
}
else
{
       False statement - 1;
}

How does Switch statement differ from Nested if

C Program example List

Google+ Badge