answersLogoWhite

0


Best Answer

The if/else ladder construction is not better than a switch. However, in some cases one is preferred. Switches for instance usually execute faster since the compiler can optimize such constructions better. This is because the compiler doesn't have to take into account any programmer forced orders of execution.

The if/else ladder is preferred where the conditions to be checked are not fixed.

So, it all depends on the situation.

User Avatar

Wiki User

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

Wiki User

12y ago

syntax and sematics

and

both are control flow statements

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why else if ladder bettar than switch?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the difference between switch case and if else?

If else can have values based on constraints, where as switch case can have values based on user choice.In if else, first condition is verified, then it comes to else whereas in the switch case first it cheaks the case and then it switches to that particular case.


What are the disadvantages of switch statement in C-language?

In some languages and programming environments, a case or switch statement is considered easier to read and maintain than an equivalent series of if-else statements, because it is more concise. However, when implemented with fall-through, switch statements are a frequent source of bugs among programmers new to the switch statement.


Is the load prong on a toggle switch the constant power source?

No the power comes from something other than the switch.


What are five advantages to using case structure to program multiple alternative decisions?

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.


What does the switch statement in JavaScript do?

The JavaScript switch statement is nothing more than a easy replacement for a series of if-then-else statements. Here's an example. var chicken; switch( chicken ) { case "fried": console.log('Fried chicken!'); break; case "fricassee": console.log('Fricassee!!!!!!!!'); break; case "egg": console.log('Which came first?'); break; default: console.log( 'With its head cut off.' ); }//end switch This statement takes a variable, then compares it to the values of each "case." When it finds a matchin value, it executes the code in that case statement. It will execute until it hits the "break" statement, so if you skip a break, then the code will continue straight through. This is the same structure as: if ( chicken "egg" ){ console.log('Which came first?') }else{ console.log( 'With its head cut off.' ); } As you can see, the switch statement is simpler, easier to read, and easier to maintain.

Related questions

Is heat pump bettar than an electric heater?

A properly installed heat pump uses about one third of the electrical energy to produce the same amount of heat.


How do you turn off runescapes chat?

Just switch the chat to Clan or anything else than "all"


Walking up a slope is easier than climbing a ladder Why?

The ladder is set at a steeper angle


Is there anything else I am missing the wipers and wiper fluid went out at the same time i replaced the control modulefuses and relay under the dash What else can i do?

more likely to be the wiper switch than anything else


A ladder is leaning against a building so that the distance from the ground to the top of the ladder is one foot less than the length of the ladder. Find the length of the ladder if the distance from the bottom of the ladder to the building is 5 feet?

A. 11 feet B. 13 C. 12 D. 14.


How do ladders work?

The main purpose of a ladder is to allow people to get higher than they can reach. A ladder works by leaning it up against a solid surface and then the person climbs the ladder using the rungs.


Why is it safer to use a ladder than to walk on the ice?

If you lay the ladder down on the ice then crawl along it, your weight is spread over a larger area and the ice is less likely to break. If someone is holding the ladder, it gives you something to pull yourself out with if it does break.


Why do you say 3 foot ladder instead of 3 feet ladder?

6


A painter is standing at the base of a ladder that is leaning against the side of a house What angle do the ladder and the house form?

It can be any angle that is more than zero degrees and less than 90 degrees. <><><> It will be an ACUTE angle, and if the ladder is placed properly (1 ft out for each 4 ft up) the angle between wall and ladder will be ABOUT 18 degrees.


Does a step-ladder weigh more or less than a kilogram?

It depends on how large the step-ladder is and what it is made of.A typical 4 or 5 foot ladder made of wood or metal will usually weigh much more than a kilogram. A tiny, miniature, decorative, model or special-purpose step-ladder could conceivably weigh less.


What is the difference between switch case and if else?

If else can have values based on constraints, where as switch case can have values based on user choice.In if else, first condition is verified, then it comes to else whereas in the switch case first it cheaks the case and then it switches to that particular case.


Why does lying on a ladder help you to reach someone trapped in thin ice?

If you laid the ladder flat on the ice and wanked on the ladder rather than the ice, then your weight would be spread over a much larger area than that of just your feet. It would then be less likely that you would break the ice yourself.