๐ Day 22 of My Automation Journey โ Switch Case Statement in Java
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 Cas...

Source: DEV Community
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 {} are mandat