0

Switch vs if statement

As far as I can tell, it seems that you can use the switch and if statements to achieve the same results. Am I missing something, or are they more or less interchangeable?

5th Jun 2020, 11:51 AM
Sam
5 Respostas
+ 3
Not every language allows the same types for switch. In C and C++, you can only use integer types including char.
5th Jun 2020, 12:37 PM
HonFu
HonFu - avatar
+ 2
wow thank you all for the quick responses. Seems a but clearer now
5th Jun 2020, 12:44 PM
Sam
+ 1
switch can only use integer values and if statements can use any type of value. I hope I was helpful :)
5th Jun 2020, 12:09 PM
Alexandre
Alexandre - avatar