Question

Locked

I have a question about using break in an if else statement.

By DHCDBD ·
I am working on a mapper for the PC xbox controller to a Saitek p2600 controller.

The original C++ code that I inherited/obtained used numerous switch statements. As much as I can, I am removing the switch statements for faster execution with if statements.

In one of the statements, I am trying to jump over the following else if statement without have to resort to a jump or goto statement.

This is the code block:
LONG v2=0;
LONG offset=0;
LONG scaling=1; // must be initialized and not null (divide by 0)


//Full range
if (triggerType == AXIS || triggerType == SLIDER) {
scaling = 256; offset = 32768; break;
}
// Half range
else if (triggerType == HAXIS || triggerType == HSLIDER) {
scaling = 128; offset = 0;
}


v2 = (v + offset) / scaling;


Will that break jump out of the else statement, or will it only cause leaving the initial if loop statement it is in? Using the break statement decreases the compiled code by 1 k from 24 k to 23 k and resolves another problem, but those I can work with later. What I want to do is to leave the if else if one of the first two conditions is true.

This is what I am changing it from:
LONG v2=0;
LONG offset=0;
LONG scaling=1; // must be initialized and not null (divide by 0)

switch (triggerType) {
// Full range
case AXIS:
case SLIDER:
scaling = 256; offset = 32768;
break;
// Half range
case HAXIS:
case HSLIDER:
scaling = 128; offset = 0;
break;
default:
scaling = 1; offset = 0;
break;
}

v2 = (v + offset) / scaling;


And no, it is not a school exercise. I am modifying an xbox controller emulator to work with a Saitek controller for the game Nitronic Rush.

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Share your knowledge
Back to Windows Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums