Pages

This blog is under construction

Thursday, January 3, 2019

Selection Statements

                  Previous                                                                     Next
A switch statement is used for multiple-way selections that will branch into different code segments based on the value of a variable or expression. This expression or variable must be of integer data type.
Syntax:
switch( expression ) {
                 case expression1: statements1; break;
                 case expression2: statements2; break;
                 case expression3: statements3; break;
                            .
                            .
                            .
                case expression N: statements N; break;

               default : default statements;
                }
Flowchart:



Using break keyword: If a condition is met in switch case then execution continues on into the next case clause also if it
is not explicitly specified that the execution should exit the switch statement. This is achieved by using break keyword.

What is default condition: If none of the listed conditions is met then default condition executed.

 Previous                                                                     Next

No comments:

Post a Comment