#12 Switch Case Statement in Java

Publicado em: 25 Agosto 2023
no canal de: Nilesh Kavankar
88
0

In this lecture we will be discussing:
1) What is switch statement?
2) why we need switch statement?
3) Syntax of switch and example
4) Need of break
5) Need of default

Java Switch Statement:
It executes one statement from multiple conditions.
It is like if-else-if ladder statement so Instead of writing many if..else statements, we can use the switch statement

Syntax:
switch(expression)
{    
case value1:    
 //code to be executed;    
 break;  //optional  
case value2:    
 //code to be executed;    
 break;  //optional  
......    
    
default:      //optional  
 // code to be executed if all cases are not matched 
}  

How Switch in Java works:
The expression is evaluated once & value of the expression is compared with the values of each case
If there is a match with case value, then the associated block of code is executed.


Nesta página do site você pode assistir ao vídeo on-line #12 Switch Case Statement in Java duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Nilesh Kavankar 25 Agosto 2023, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 88 vezes e gostou 0 espectadores. Boa visualização!