dimanche 12 juillet 2020

Should I use an if then statement or a switch statement?

I am new to java development, having done python for about a year. I understand how switch statements are used when comparing a variable to multiple different values, but my question is if there are only two different values, (ie. x == 1 or x == 0) is it more optimal to use a switch statement or an if else statement? i understand how both work but I just can't figure out if there would be a difference in this case, and if there is what it would be.

Aucun commentaire:

Enregistrer un commentaire