Monday, 6 February 2017

switch control in C and C++.

Tags

Switch condition


switch condition is used to print multiple value as  a code or showing different code in same programme.

syntax;

switch(expression)
{
case constant:
code;
break;
case constant:
code;
break;
case constant:
code;
break;
default:
code;
}

different cases are used to show different result.
constant are used to identify each code and it is not compulsory to have constant as a number or character we can take constant as a integer or character as we wish but we did not take constant as a float , like 1.2,1.3 etc.
it is also not compulsory to have constant on a sequence.
 we can use switch condition in place of nested-if statement, we can not use nested -if statement in longer programme because it is difficult to read programme.