Structure _If_ Statement
- You have a conditional jump over consecutive statements.
Negate the conditional expression and make statements the conditional clause.
if(cond)
goto skip;
/* cond is false */
...
skip:
⇓
if(!cond) {
/* cond is false */
...
}
Motivation
If-then statements are translated by the compiler as a conditional jump over the statements that constitute the then clause. This refactoring recovers the original control structure.
Mechanics
Negative the if statement condition.
- Replace the jump by the skipped statements.
- Remove the jump label, if not longer used.