0
When is else if used instead of if else ?
2 Réponses
0
if else is used when you want to check for 1 thing and everything else can fall under the else. else if is used if you are checking multiple things.
Example, you have a program checking to see if user inputs yes or no. You'd do, if (blahblah == yes) do this, else if(blahblah == no) do this. Can even add an else at the end in case they put anything else that doesn't fit.
Example of just an if else. Your program asks a question and you only want the correct answer. if(answer == correct) yay, else(doesn't matter what they put, if it's not correct it's wrong) you're answer isn't correct.
0
when you have many conditions