answersLogoWhite

0

Switch is an alternative to using a long sequence of if...else if... statements where each conditional expression is essentially the same, evaluating to the same data type but with different values.

For instance:

if(x==1) statement_1;

else if(x==2) statement_2;

else if(x==3) statement_3;

else statement_4;

The above can also be written:

switch(x)

{

case(1): statement_1; break;

case(2): statement_2; break;

case(3): statement_3; break;

default: statement_4;

}

Most would regard the second version as more readable as there's only one conditional expression to evaluate.

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

What is the deffernce of the switch statement and the if statement in c plus plus?

If statement is single selection statement,whereas the switch statement is multiple selective.


What is the function of visual c plus plus switch condition?

The switch / case statement.


What programming languages use a C switch statement?

There are two programming languages which use a C switch statement. The two languages are C and C++, hence the name C switch statement. There may be more, but those are the most obvious ones


Which statement is not frequently used in C plus plus?

The goto statement.


Control statement in c plus plus?

Control statements are statements that alter the flow of execution according to the evaluation of an expression (the condition). The C++ control statements are ifstatements, switch statements and the tertiary conditional operator, ?:.


Calling a function from switch in C?

Yes, you can call a function from within a switch statement in C. switch (i) { case 0: function1(i); break; case 1: function2(i); break; default: function3(i); break; } When the function returns, you will still be in the switch statement.


What is the role of object in c plus plus?

An object in C++ is an instance of a C++ class.


Basic control structure available in c plus plus?

The basic control structure in C++ is the if statement.


What is the purpose of break statement in c?

The break statement exits control of the innermost for, while or do-while loop, or switch statement.


A c plus plus statement that invokes a function is known as?

...a function call.


Which statement in C plus plus is used to implement a decision structure in its simplest form-that of choosing between two alternatives?

if (condition) statement else statement;


What are the three selection structures available in C plus plus?

if while switch