0

Switch what is these?

11th Jan 2017, 12:05 PM
Ravi
Ravi - avatar
6 Respostas
+ 2
It's like if but with multi choice. You can use it if you whould need to write multi if statement.
11th Jan 2017, 12:10 PM
Marcin Barańczyk
Marcin Barańczyk - avatar
+ 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.
11th Jan 2017, 12:18 PM
Marcin Barańczyk
Marcin Barańczyk - avatar
+ 1
Pretty much it will go from one statement to the other so long as you have a break at the end
11th Jan 2017, 4:26 PM
John
0
what is a case....
11th Jan 2017, 12:13 PM
Ravi
Ravi - avatar
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.
11th Jan 2017, 6:23 PM
Shervin Jarrahi
Shervin Jarrahi - avatar
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
11th Jan 2017, 6:44 PM
Shervin Jarrahi
Shervin Jarrahi - avatar