Conditional Statements in C – II

What is nested if / ladder if statement?

Nested if can be stated as the ladder or continuous utility of conditional statements. It could be any conditional statement inside any other conditional statement like if statement inside an if else statement or if else statement inside an if else statement.. and many other combinations. There is no limit of the number of levels that can be nested.

Syntax:

if(condition)

{

}

else

{

   if(condition)

  {

  }

}

Note: any one body is executed over here.

What is switch statement?

Switch is used when there are more number of options ( called as cases here ). The case is executed when the condition is true that is if the expression matches with the case label name and not executed when the condition is false. This makes a multiway selection that is between many alternative functions.

Syntax:

switch(expression)

{

case labelname 1:

case labelname 2:

break; 

default:

Note: 

1. There is no limit of number of cases.

2. When any of the case is executed the consecutive cases are also executed that is if second case is executed third and fourth and so on… if present. To avoid tis ‘break’ is added, this makes it out of switch and consecutive cases are not executed. This is not mandatory.

3.  The case lebelname must be integral type or character type.

4. When none of the cases are matched the ‘default’ case is executed. It is not mandatory and can be placed anywhere in switch.

What are ASCII Values?

ASCII stands for American Standard Code Information Interchange. These are the pre-defined integral values fixed for all input characters given to the system cause system can understand only binary input and only integers can be converted to binary digits.

Example:   ‘A’ – 65      ‘a’ – 97