0
Switch what is these?
6 Respostas
+ 2
It's like if but with multi choice. You can use it if you whould need to write multi if statement.
+ 1
case is statement in which you put value that will be cheked by switch statement. if the value you gave in case is equal with the value used in swich program will run code from case statement. remember about break; statement. if you will mot inclide break the program will execute all remaining code lines in swich statement.
+ 1
Pretty much it will go from one statement to the other so long as you have a break at the end
0
what is a case....
0
Both switch and if are the same.
Switch is better than if in 2 case :
1 - it makes the program simpler
2 - it avoids using too many if-else structures.
0
The switch structure :
switch (variable name) {
case value : statment ; break ; //this is similar to if
.
.
.
default : statment ; //this is similar to else
}
// break is for exiting the switch if any of the cases are correct