switch vs if-else

Posts 16–19 of 19 · Page 2 of 2
Just found this small article, Seems I am not the only one who tests loops for performance, K given the fact that its .net he is talking about and is no way meant to be compared to C++ but it just goes to show that the Switch Statement is fast just like in Delphi

Switch vs If
they both work the same.
Even though "swirch " may be faster,
it not faster by much.
Its barely enough to notice to humans perception.
Plus using switch you may lagg if you dont
do it the right way, causing your memory to
just pour out everywhere (mem leaks) lol

I myself preffer to use IF and ELSE
its a lot more code friendly to people that are just learning.
Quote Originally Posted by Xlilzoosk8rX View Post
they both work the same.
Even though "swirch " may be faster,
it not faster by much.
Its barely enough to notice to humans perception.
Plus using switch you may lagg if you dont
do it the right way, causing your memory to
just pour out everywhere (mem leaks) lol

I myself preffer to use IF and ELSE
its a lot more code friendly to people that are just learning.
i dont see what is so confusing about
switch(variable)
{
case 1:
//whatever
break;

case 2:
//whatever
break;

default:
//whatever
break;
}
I myself preffer to use IF and ELSE
its a lot more code friendly to people that are just learning.
I have to disagree on that, Switch is clearly more readable than if statements, its more logical for new people coming into programming, People using if statements all the time have more than likely picked this habit up from other sources, for example programmers who have come from vb to C++ and then the new person learning c++ has picked up the habit.

c++ - Switch vs if-else - Stack Overflow
Posts 16–19 of 19 · Page 2 of 2

Post a Reply

Tags for this Thread

None

Talk with us