answersLogoWhite

0


Best Answer

1. Switch/case structures yield cleaner, more maintainable code than equivalent nested if..else statements.

2. With if...else statements, the programmer must put the most likely cases first. With switch/case structure, the order of the cases is immaterial.

3. The default switch/case label can be placed anywhere. With if...else, the default must be placed last.

4. Where multiple cases contains common (duplicate) code, omitting the break statement allows execution to fall through to the common code. With if...else, the common code must be duplicated.

5. Switch/case is as fast if not faster than equivalent nested if...else statements. However, modern compilers can optimise nested if...else statements into an equivalent switch/case structure wherever appropriate, thus the speed advantage is much less of a concern these days.

Whenever you have the option of using one or the other, use switch/case if only to make code more readable. However, there will be cases where an if...else may be more readable. For instance, consider the following examples:

void f (const char c) {

if (c>='a' && c<='z') {}

else if (c>='A' && c<='Z') {}

else if (c>='0' && c<='9') {}

else {}

}

void g (const char c) {

switch (c) {

case 'a': case 'b': ... case 'y': case 'z': {} break;

case 'A': case 'B': ... case 'Y': case 'Z': {} break;

case '0': case '1': ... case '8': case '9': {} break;

default: {}

}

}

Typing out all the cases in function g would obviously be tiresome and error prone compared to the succinct statements of function f. However, a good compiler will generate the same code regardless of which function you use, so the choice is simply one of which is the most readable.

User Avatar

Wiki User

8y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

9y ago

One of the advantages of using a case structure is creating logic flows. Other advantages include low CPU overhead and they are easy to understand.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are five advantages to using case structure to program multiple alternative decisions?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are some disadvantages of using case structures to program multiple alternative decisions?

Using case structures becomes difficult when programming multiple alternative decisions. Instead of listing each of the steps and executing them individually, it is easier to make decision structures and loops.


What are the five advantages and five disadvantage of using case structures to program multiple alternative decision?

what are five advantages and five disavantages of using case structures to multiple alternative dicisions


What structure allows you to test the value of a variable or an expression and then use that to determine which statement or set of statements to execute?

multiple alternative decision structure / case structure


What control structures is a multiple -branch decision mechanism capable of more than three decisions?

The case structure


what control structures is a multiple-branch decision mechanism capable of more than three decisions?

The case structure


Does the multiple selves theory apply to brand decisions for consumers?

does multiple selves theory apply to brand decisions for consumers? does multiple selves theory apply to brand decisions for consumers?


What is the correct word for past tense of multiple decisions?

"Multiple" is an adjective and "decisions" is a noun. There is no past tense for either. "Decide" is a verb though, the past tense being "decided." You could say "I made multiple decisions."


Advantages of IRR?

Can be an indicator for choosing investments - if IRR rate is higher than the cost of the money (or an alternative investment) than it is worth investing in the project if there is no multiple IRR.Read more to get the disadvantages also: What_is_advantage_and_disadvantage_of_IRR


What is fixed alternative questions?

Basically, a multiple choice question.


What is fixed-alternative questions?

A fixed-alternative question is a type of multiple-choice question where respondents must select one answer from a list of predetermined options. It provides a clear set of choices for participants to choose from, making it easier to analyze and compare responses.


What is a fat with a multiple ring structure?

cholesterol


What are the advantages of multiple can combustion chamber?

Cheap to produce.