Java switch statement

preview_player
Показать описание
Java tutorial for beginners playlist

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.

Switch statement in java provides a way to select one of the many different actions.

You must use a break statement after each case block to keep execution from faillng through remaining test cases.

If multiple cases need to have same action, then they can be stacked together

Switch statement rules
1. Multiple case labels but only a single default label.
2. Default label executes when no matching value is found in the case labels.
3. Use break statement to exit a switch case
4. Without break it will just fall through
5. Prior to Java 7, switch control expressions could be integer/character only. Now, String objects are allowed
6. Case statements are executed in sequential order.
7. Use if-else statement when test expressions are based on ranges of values or conditions
8. Use switch to improve readability and where test conditions are based on single integer, enumerated type or string object
Рекомендации по теме
Комментарии
Автор

Plz don't forget to hit the like button if you like .

raqibul
Автор

I have a question..when break statement is removed after the switch statement then we see that after matching the condition it falls through.. then why printing default statement instead of the matched statement followed by the below statements till default? Please answer the question

anasuadas