0
Help understanding switch please
Didn't understand the logic of this.
2 odpowiedzi
+ 6
The switch statement evaluates an expression, matching the expression's value to a case clause, and executes statements associated with that case.
0
If else if else if else.... Switch creates cases to match. Reads easily, makes more sense, less code. If you have to test if someone is younger than 18 would it not make more sense to check if person <18 than if person 10, else if person 11 etc. Switch tests multiple conditions until it finds true or defaults/breaks, basically to answer you in one sentence, use switch when you have more than 3-4 conditions to test otherwise you end up with nested, long confusing if else tests.