write two difference between if-else-if and switch state
Answers
Answered by
1
IF ELSE IF
A conditional statement that executes a different set of statements based on the condition that is true or false
If block vl be executed when it condition is true
Condition in if block is false then it checks for the condition in else if block
Conditions of both if block and else if block or wrong then it goes with the else block and executes
SWITCH :- conditional statement check to check the value for the variable and compare it with all the cases
If the value is matched with any of the case, then it’s corresponding statements will be executed
I hope it’s helpful
A conditional statement that executes a different set of statements based on the condition that is true or false
If block vl be executed when it condition is true
Condition in if block is false then it checks for the condition in else if block
Conditions of both if block and else if block or wrong then it goes with the else block and executes
SWITCH :- conditional statement check to check the value for the variable and compare it with all the cases
If the value is matched with any of the case, then it’s corresponding statements will be executed
I hope it’s helpful
Similar questions