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
}
Comments and Additional Information
Have some code to share? Or additional information? Respond here:
You need to be logged in to save a response on this page. The response must be constructive, helpful, supplimentary or to correct the existing video, code or narrative content.