Computer Science, asked by anjalisingh9742, 6 months ago


a Differentiate between if and switch statements with example​

Answers

Answered by Cricketer45
1

Differences b/w if-else and switch statement. Based on the result of the expression in the 'if-else' statement, the block of statements will be executed. If the condition is true, then the 'if' block will be executed otherwise 'else' block will execute. The switch statement contains multiple cases or choices.

Hope it helps....... ❤️

Answered by samikshajadhav16
0

Explanation:

The main difference between them is, if-else statement evaluates a condition and if the result turns out to be true then only the if block would be executed otherwise else block.

SWITCH STATEMENT

A switch statement cannot have two or more cases with identical value .

Switch statement in C tests the value of a variable and compares it with multiple cases. Once the case match is found, a block of statements associated with that particular case is executed. Each case in a block of a switch has a different name/number which is referred to as an identifier.

IF-ELSE STATEMENT

Such situation doesn't occur in If

the 'if-else' statement, the block of statements will be executed. If the condition is true, then the 'if' block will be executed otherwise 'else' block will execute.

Similar questions