0

What is the point of the Switch statement in C++?

In the C++ lesson, the 'switch' function is described as a more elegant option than using multiple 'if' functions. I've made a basic ''if' based calculator, and my code is much longer and looks much messier with the 'switch' function in place of 'if' functions. It doesn't seem to give an output and faster either, so why use it?

6th Sep 2018, 8:19 PM
Jake
Jake - avatar
1 Respuesta
+ 10
if (a == b || a == c || a == d ...) {} switch (a) { case b: case c: case d: ... break; case e: ... } /* its just a better way to split into cases: -if a is b or: if a is c or: if a is d... *becomes -in case a is b or c or d*/
6th Sep 2018, 8:25 PM
Valen.H. ~
Valen.H. ~ - avatar