When to use switch statements

Al Heck
May 26, 2021

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.

--

--

Al Heck

Unity Developer and Software Engineer who loves making games with GameDevHQ