answersLogoWhite

0


Best Answer

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.

User Avatar

Wiki User

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

Wiki User

11y ago

Both are logic control statements (or "branch statements", if you prefer). It is possible to write all switches as a series of if-then-else statements, but not all if-then-else statements may be written as switch statements.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

In if there is no use of case and break.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the similarity between 'if' statement ans 'switch' statement?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering
Related questions

What value is assigned to the type int variable ans in this statement if the value of p is 100 and q is 50?

It is not possible to answer this question without knowing the actual expression used in the assignment statement. The following are merely example expressions showing some of the values that could be assigned to ans: int ans, p=100, q=50; ans = p + q; // ans = 150 ans = p * q; // ans = 5000 ans = p - q; // ans = -50 ans = p / q; // ans = 2 ans = p % q; // ans = 0


What is the similarity between absolute ans relative dating?

It is the method of descovering the methodof the age of something... I think it is the age of the fossil u are trying to find out


How you use multiple programs in switch statement in c language?

program#include#include#includevoid main(){int a,b,ans,ch;clrscr();printf("enter the value of a and b");scanf("%d%d",&a,&b);printf("1.Addition");printf("\n2.Subtraction");printf("\n3.Multiplication");printf("\n4. exit");printf("enter your choice");scanf("%d",&ch);switch(ch){case 1:ans=a+b;printf("\nAfter Addition:%d",ans);break;case 2:ans=a-b;printf("\nAfter Subtraction:%d",ans);break;case 3:ans=a*b;printf("\nAfter Multiplication:%d",ans);break;case 4:exit(0);break;}getch();}


Where is the neutral switch located on a 1996 Geo Tracker?

There is no neutral safety switch it is a clutch position switch ans is loacted in the floor in front of the clutch pedal


Is engineering a poor career choice?

Short Ans YES! Long Ans It depends, where R U? Do U want to work in the USA? How old R U? What kind of Engineer where U thinking about? Now ans these ques and we can have a real ans that applies to U not just a blanket statement.


Difference between section and article?

no ans


1997 Toyota rav4 cooling fans come on as soon as the switch is turned on ans stay on until key is turned off what is the problem?

coolant temp switch or fan relay are bad.


What was the relation between hazrat Muhammad saw and hazrat ans bin malik RA?

Mother of H. Ans gave her son to prophet .H. Ans is narrator of large number of Hadith. He is companion of Prophet .


What is the tube after the epididymis?

The vas deferens is between the epididymis ans the urethra.


What is Halfway number between 47 and 91?

Ans- its 69


What is the difference between primary ans secondary industry?

secondary is cooler


What does main idea ans details mean?

Main Idea and details is a short statement about what the story/paragraph is about. Simpily it has 3-2 facts in it