+ 4

What is use of switch statement?

2nd Mar 2017, 3:09 AM
🎆Sourav Subhakant Dash🔥🔥
🎆Sourav Subhakant Dash🔥🔥 - avatar
2 Antworten
+ 1
It gives you the ability to do multiple if statements in a more organized fashion. Instead if typing if(x == y) then { /*code*/ } else if (x == b) then { /*code*/ } you can type switch(x){ case y: //code break; case b: //code break; } This makes the code so much more clean. There is also a default that can be added. I am not an expert on it, but it explains more in the course. (By the way, I wrote that Switch code excerpt using c++ so it might not be the same for whichever language you are using). This may seem unimportant, but it definetly is more reliable with the more cases you want to test. Hope this helped.
2nd Mar 2017, 3:23 AM
Rain
Rain - avatar
0
It makes code seen easy to understand and not too clumsy... such as if ..else if... else.. it is easy ...
2nd Mar 2017, 3:58 AM
Bibek Magar
Bibek Magar - avatar