
π 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 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




