answersLogoWhite

0

Switch Case is used when you want to check whether a certain variable is equal to a set of particular values and theres a different task to do for each value.

If-then-else is can be used to check for anything, including a range of values and perform a specific task if the condition is met.

For eg:

switch(c)

{

case(1): task1(); break;

case(2): task2(); break;

case(3): task3(); break;

default: task9(); break;

}

if(c>=1 && c<=9)

task1();

else

task2();

Note: You cannot use >= or <= in switch case.

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

What is the difference between If-else and Switch-case in Java?

The if statement is used to select among two alternatives. It uses a boolean expression todecide which alternative should be executed. The switch statement is used to select among multiple alternatives. It uses an int expression to determine which alternativeshould be executed.


What is the difference between if-else and else-if?

if-else implies a first statement, while else-if implies that we would know what else is but we don't because else is defined by if.


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.


Difference bitween switch and if statement?

Switch - Case statement is similar to the if - else if statement construct in the way it operates. Both are used to check for a sequence of conditions and execute a piece of code based on success of the matching condition. Difference - We need a break statement at the end of every case block to ensure that further cases are not executed in case of success of condition in one case block.


How if else if statement is differ from switch in general in java?

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.


Which one gives better execution to the program switch or if else?

There is no difference between switch and if-else. A modern optimizing compiler should be able to generate the same code in both cases.


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.


What is the difference between hypothesis and inference?

A hypothesis is a statement of fact or belief upon which further conclusions can be drawn. An inference is the meaning that I attribute to someone else's statement or action.


Difference between if else and else if?

what is diffrence between if else and else if


Write an equivalence of switch statement and if statement?

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


What is the Difference between program and flowchart?

Flowchart it is diagrammatic Program it is coding. A flowchart is drawn out on paper, and shows the logic of an if/then/else statement. The programming actually is the if/then/else, not just the logic.