switch vs if-else

Posts 115 of 19 · Page 1 of 2
switch vs if-else
uhm... which one would be better to use for a menu hack?
BTW these are random examples I made up...
switch -

Code:
switch (x) {
  case 1:
    cout << "x is x";
    break;
  case 2:
    cout << "x is xx";
    break;
  default:
    cout << "value of x unknown";
  }
if-else -
Code:
if (x == 1) {
  cout << "x is 1";
  }
else if (x == 2) {
  cout << "x is 2";
  }
else {
  cout << "value of x unknown";
  }
YES I KNOW THEY ARE EQUIVALENT, BUT WHICH IS MORE EFFICIENT?
if i like (If)
yeah, me too, but which is more efficient?
you do understand the efficiency difference is so negligible that if you don't even know C++ the chances you''l be able to use it effectively are very slim and even if you did, it's quite pointless. Use whatever makes sense. Don't make nonsensical error-prone code to scrape out 1ms of a difference, your much more likely to cause memory leaks or repeatedly create large data structures on the stack instead of just accepting them as a parameter or global variable and other errors doing that and then that 1ms difference is pointless.
Quote Originally Posted by why06jz View Post
you do understand the efficiency difference is so negligible that if you don't even know C++ the chances you''l be able to use it effectively are very slim and even if you did, it's quite pointless. Use whatever makes sense. Don't make nonsensical error-prone code to scrape out 1ms of a difference, your much more likely to cause memory leaks or repeatedly create large data structures on the stack instead of just accepting them as a parameter or global variable and other errors doing that and then that 1ms difference is pointless.
In case he does not make memory leaks large data structures and stuff.

Did you try adding "Sleep(1);" inside of "Present", "BeginScene" or "EndScene" the difference is VERY LARGE.
Switch allows you to fall through, if doesn't. That's about the only difference.

switch (crosshairType)
(
Case 3: // vertical + horiztaonl
// vertical
Case 2:
// horzintal
break;
Case 1: // vertical
//vertical
}

Typed on phone, sorry about the crap example.. I would have gown you a real code snippet of mine but yeah.

Quote Originally Posted by topblast View Post


In case he does not make memory leaks large data structures and stuff.

Did you try adding "Sleep(1);" inside of "Present", "BeginScene" or "EndScene" the difference is VERY LARGE.
--" irrelevant. And sleeping DOES NOT stop memory leaks, only cleaning up after your shit does.
wrong section buddy
This is a "Hack Coding" section. You are asking a programming question. They are two different things. Well not to you . But yeah wrong section
[IF] is more good for me!!
What why06jz said, He is right use the function that is suited to project and make sense.
Quote Originally Posted by why06jz View Post
you do understand the efficiency difference is so negligible that if you don't even know C++ the chances you''l be able to use it effectively are very slim and even if you did, it's quite pointless. Use whatever makes sense. Don't make nonsensical error-prone code to scrape out 1ms of a difference, your much more likely to cause memory leaks or repeatedly create large data structures on the stack instead of just accepting them as a parameter or global variable and other errors doing that and then that 1ms difference is pointless.
Thanks, I actually read all of dat...

Quote Originally Posted by GodHack2 View Post
wrong section buddy
K sorry, didn't know.

Quote Originally Posted by _Fk127_ View Post
This is a "Hack Coding" section. You are asking a programming question. They are two different things. Well not to you . But yeah wrong section
Yeah, realise that now

Ah, thanks blast.
Adding Sleep inside of any D3D function hook might single handedly lag your hack to the point of being unusable.
I would only use switch statement when making a speed hack or some of the sort that has different speed/Values but other then that if statemant
Posts 115 of 19 · Page 1 of 2

Post a Reply

Tags for this Thread

None

Need help?