Skip to content
Advertisement

Go to default case from another case in PHP

It is possible to go to default case from within some other case like this?

JavaScript

I tried to remove the else and was expecting that it would continue evaluating all following cases until default but it gets into case 1 then. Why is it so and how can I get to the default one?

Advertisement

Answer

Yes you can if you reorder the case statements:

JavaScript

Why is it so: it is defined, if you de not have a break statement the next case will be executed. If there is no more case, the default will be executed if one is defined

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement