When to use switch statements

If you have more than 2 if else statements, use a switch statement since it’s cleaner to read.

This if statement above means exactly the same as the statement below.

Keep in mind, when you declare in the switch statement the variable, the case isn’t always 1 or 0, it’s the variable value. So in this case, 50, 100, or could be a string, etc.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Al Heck

Unity Developer and Software Engineer who loves making games with GameDevHQ