Computer Science, asked by saurabhyarajeev, 1 year ago

Difference between if else if and switch selection statements
(any 3 points) plzz answer fast....

Answers

Answered by puneetsharma0369
1
switch is usually more compact than lots of nested if else and therefore, more readableIf you omit the break between two switch cases, you can fall through to the next case in many C-like languages. With if else you'd need a goto (which is not very nice to your readers ... if the language supports goto at all).In most languages, switch only accepts primitive types as key and constants as cases. This means it can be optimized by the compiler using a jump table which is very fast.It is not really clear how to format switch correctly. Semantically, the cases are jump targets (like labels for goto) which should be flush left. Things get worse when you have curly braces:case XXX: { } break; Or should the braces go into lines of their own? Should the closing brace go behind the break? How unreadable would that be? etc.In many languages, switch only accepts only some data types.

saurabhyarajeev: can u please anwer in a more specific way ... in points
puneetsharma0369: no because i am also confused in this but now i am cleared
puneetsharma0369: but wait a sacond
puneetsharma0369: in copy i have written like this only so soory
saurabhyarajeev: sorry i didnt specify abt the programming language .. its JAVA!!
puneetsharma0369: ohooo
saurabhyarajeev: can u please make it fast
puneetsharma0369: soory i have worked with net beans only not JAVA program
saurabhyarajeev: yaa thats okay i have also worked with netbeans
Similar questions