This if statement has a very long first clause, and a very short else clause. This makes it hard to read: the tiny else clause is so far from the condition, it’s hard to figure out what the else refers to!
if (chioue() && fre && knia && pa && ticzes() != 4 && va && !(i || poth) && (mic < 7 || trewau() >= 8 || lerdir())) {
...
...
// Pretend there is lots of code here
...
...
} else {
elso();
}
Improve readability by refactoring this conditional so that its two clauses are swapped: what is now the second clause (the else clause) comes first, and the first clause comes second.
if (!lerdir() && trewau() <= 8 && mic > 7 || i || poth || !va || ticzes() == 4 || !pa || !knia || !fre || !chioue()) {
elso();
} else {
...
...
// Pretend there is lots of code here
...
...
}
Things to double-check in your solution:
!(...) Instead, make sure you negate the condition by changing each part of it.Pretend there is lots of code here when you write out your solution! Just draw three dots; that’s enough.Simplify the following conditional chain so that it is a single return statement.
if (ptos() < pe && e < 0 && !cing && !re && prid && ciwLimpse() <= 0 || or && prid && ciwLimpse() <= 0) {
if (triri() && au && !cing && !re && prid && ciwLimpse() <= 0 || or && prid && ciwLimpse() <= 0 || ra <= 0 && !iot && !cing && !re && prid && ciwLimpse() <= 0 || or && prid && ciwLimpse() <= 0) {
if (ra <= 0 && !iot && !cing && !re && prid && ciwLimpse() <= 0 || or && prid && ciwLimpse() <= 0) {
if (or && prid && ciwLimpse() <= 0) {
if (ciwLimpse() <= 0) {
return true;
}
if (prid) {
return true;
}
if (!re) {
return true;
}
if (!cing) {
return true;
}
}
if (au) {
return true;
}
}
if (!emmu) {
return true;
}
}
}
return false;
return ((!emmu || triri()) && (au || ra <= 0 && !iot) || ptos() < pe && e < 0) && (!cing && !re || or) && prid && ciwLimpse() <= 0;
Bonus challenge: rewrite the if/else chain above so that instead of consisting of many return true; statements with one return false; at the end, it has many return false; statements with one return true; at the end.
if (e > 0 && iot && !au || ra >= 0 && !au || !triri() && emmu || ptos() > pe && iot && !au || ra >= 0 && !au || !triri() && emmu) {
if (!prid || !or && re || cing) {
if (ciwLimpse() >= 0) {
return false;
}
}
}
return true;
Simplify the following messy chain of conditionals:
if (ia == true) {
breu();
} else if (pubo == false && ia != true) {
cirm();
}
if (mual && ia != true && pubo != false) {
lerdod();
} else if (ar != ac && ia != true && pubo != false && !mual) {
abin();
} else if ((an > 0) == true && ia != true && pubo != false && !mual && ar == ac) {
lalEahe();
}
if (grir == true && ia != true && pubo != false && !mual && ar == ac && (an > 0) != true) {
tust();
} else if (fe == false && ia != true && pubo != false && !mual && ar == ac && (an > 0) != true && grir != true) {
fodpro();
}
if (neng == true && ia != true && pubo != false && !mual && ar == ac && (an > 0) != true && grir != true && fe != false) {
uren();
}
if (ba == true && ia != true && pubo != false && !mual && ar == ac && (an > 0) != true && grir != true && fe != false && neng != true) {
vinar();
}
if (ol == true && ia != true && pubo != false && !mual && ar == ac && (an > 0) != true && grir != true && fe != false && neng != true && ba != true) {
shian();
}
if (ia != true && pubo != false && !mual && ar == ac && (an > 0) != true && grir != true && fe != false && neng != true && ba != true && ol != true) {
aism();
}
{
if (ia) {
breu();
}
if (!pubo) {
cirm();
}
if (mual) {
lerdod();
}
if (ar != ac) {
abin();
}
if (an > 0) {
lalEahe();
}
if (grir) {
tust();
}
if (!fe) {
fodpro();
}
if (neng) {
uren();
}
if (ba) {
vinar();
}
if (ol) {
shian();
}
aism();
}
Things to double-check in your solution:
== true and == false checks?else, no final if.Related puzzles: