answersLogoWhite

0

An else statement is comparing to items, while a switch statement is used to compare multiple items. So if you need multiple results from one statement use a switch but for booleans or very specific functions use a if else statement.

Else If ex. if(a=6){System.out.println("It is six");} else(){System.out.println("It is not six");}

Switch ex. switch(a){ case 1: System.out.println("it is one"); break; case 2: System.out.println("it is two"); break; default: System.out.println("it is not one or two"); break; }

Basically a switch is a good way to check against a lot of possibilities.

User Avatar

Wiki User

10y ago

What else can I help you with?

Related Questions

What does default mean in switch statement?

Default clause in switch statement used to indicate that the desired option is not available with the switch case statement. it is similar to else statement of if statement which is used when the condition does not satisfy.


Write an equivalence of switch statement and if statement?

switch(ch) { case '+': ....cout <<"arithmetic operator"; ....break; //<===break is a must /// <====================other cases . . default: // <=======else }


Why you use if and else statement in c language program?

There is no "elseif" statement in C. You can only use "else" and "if" separately. This is a good reason for switch/case/break.


What is a general statement?

A general statement is something that tells you breifly what you need to do.general statements are usually in information reports or could be in some thing else like a explanation.n


What a general statement?

A general statement is something that tells you breifly what you need to do.general statements are usually in information reports or could be in some thing else like a explanation.n


What is the similarity between 'if' statement ans 'switch' statement?

A Switch statement can be considered as a series of if. else if. else statements. whatever condition is satisfied, the code block would get executed. if (cond 1) { } else if (cond 2) { } else if (cond 3) { } ...... } else if (cond N) { } else { } switch { case 1: .... case 2: .... .... case N: ... default: ... } Difference: In the if else blocks, if one condition is satisfied, all other blocks are ignored In Switch blocks, unless you have break statements inside each condition block, the subsequent blocks would not be ignored.


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.


How do you turn a if statement to a switch statement?

Old: if (condition) stmt1; else stmt2; New: int cc = (condition)!=0; switch (cc) { case 1: stmt1; break; case 0: stmt2; break; }


Can you use conditional operator in cout statement?

Yes, but 'cout' is not a statement! Examples for statements: null-statement, block, expression, if-else, while, do-while, for, continue, switch, break, return.


General syntax for if with examples?

if () orif () else examples:if (argc==1); /* null-statement */else if (argc==2)if (strcmp (argv[1], "help") /* nested if */{ puts ("Help"); } /* compound statement */else puts ("No help");else printf ("argc=%d\n", argc);


Syntax of nested if in c?

If(condition) { if-else statement; } else { if-else statement; }


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.