Programming: The If Else Condition Compared to the Switch Case Condition
Share
The if else condition can be used as an alternative to the switch case conditional statement and vice versa.
The switch case conditional statement: switch (Variable) { case FirstValue: //Code to execute when FirstValue is matched //... break; case SecondValue: //Code to execute when SecondValue is matched //... break; case ThirdValue: //Code to execute when ThirdValue is matched //... break; default: //Default code break; } The if else conditional statement: if (variable == FirstValue) { //Code to execute when FirstValue is matched //... } else if (variable == SecondValue) { //Code to execute when SecondValue is matched //... } else if (variable == ThirdValue) { //Code to execute when ThirdValue is matched //... } else { //Default code }