Back to articles
πŸš€ Day 22 of My Automation Journey – Switch Case Statement in Java

πŸš€ Day 22 of My Automation Journey – Switch Case Statement in Java

via Dev.to Beginnersbala d kaveri

Today I learned about another important decision-making concept in Java πŸ‘‰ Switch Case Statement. It is very useful when we need to compare one value against multiple options. πŸ”Ή What is Switch Case? A switch statement allows us to select one block of code from multiple choices. πŸ‘‰ Instead of writing multiple if-else, we can use switch for better readability. 🧠 Syntax switch ( expression ) { case value1 : // code break ; case value2 : // code break ; default : // default code } πŸ”‘ Important Points βœ” switch works with: int char String enum ❌ Not supported: float, double, boolean πŸ”Έ What is break? πŸ‘‰ break is used to stop execution of switch Without break, Java will continue executing next cases (fall-through) ⚠️ πŸ”Έ What is continue? πŸ‘‰ continue is NOT used inside switch directly βœ” It is used inside loops βœ” But can be used in switch only if switch is inside a loop πŸ”Έ Switch Without Braces ❗ switch ( day ) case 1 : System . out . println ( "Monday" ); ❌ This is INVALID in Java πŸ‘‰ Curly braces {} ar

Continue reading on Dev.to Beginners

Opens in a new tab

Read Full Article
6 views

Related Articles