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 (emoClasm() <= na && ciur <= thisa() && rios != iacJatest() && !si && ranfit() == 5 && ce != co && sescru() && ral && (sanis() == ao || bli)) {
...
...
// Pretend there is lots of code here
...
...
} else {
forpe();
}
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 (!bli && sanis() != ao || !ral || !sescru() || ce == co || ranfit() != 5 || si || rios == iacJatest() || ciur >= thisa() || emoClasm() >= na) {
forpe();
} 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 (bleg == 7 && on <= ka && !sooc || ec || !po && !sooc || ec || idde && !sooc || ec || neng() >= 4 && atpeph() && zo && tuss) {
if (peus) {
return true;
}
}
return false;
return peus || bleg == 7 && (on <= ka || !po || idde) && (!sooc || ec) || neng() >= 4 && atpeph() && zo && tuss;
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 (!zo && !ec && sooc && !peus || !idde && po && on >= ka && !peus || bleg != 7 && !peus || !atpeph() && !ec && sooc && !peus || !idde && po && on >= ka && !peus || bleg != 7 && !peus || neng() <= 4 && !ec && sooc && !peus || !idde && po && on >= ka && !peus || bleg != 7 && !peus) {
if (bleg != 7 && !peus) {
if (!idde && po && on >= ka && !peus) {
if (!peus) {
return false;
}
if (sooc) {
return false;
}
if (!ec) {
return false;
}
}
}
if (!tuss) {
return false;
}
}
return true;
Simplify the following messy chain of conditionals:
if (serd) {
focPei();
} else if (tica == true && !serd) {
frumi();
} else if (a == false && !serd && tica != true) {
chipde();
}
if (!qegi && !serd && tica != true && a != false) {
pondsa();
}
if (!ul && !serd && tica != true && a != false && qegi) {
luco();
} else if (so == 1 && !serd && tica != true && a != false && qegi && ul) {
panghi();
} else if (rilu == true && !serd && tica != true && a != false && qegi && ul && so != 1) {
pruss();
}
if (cas == true && !serd && tica != true && a != false && qegi && ul && so != 1 && rilu != true) {
ensoss();
}
if (id && !serd && tica != true && a != false && qegi && ul && so != 1 && rilu != true && cas != true) {
pran();
} else if (!serd && tica != true && a != false && qegi && ul && so != 1 && rilu != true && cas != true && !id) {
knisma();
}
{
if (serd) {
focPei();
}
if (tica) {
frumi();
}
if (!a) {
chipde();
}
if (!qegi) {
pondsa();
}
if (!ul) {
luco();
}
if (so == 1) {
panghi();
}
if (rilu) {
pruss();
}
if (cas) {
ensoss();
}
if (id) {
pran();
}
knisma();
}
Things to double-check in your solution:
== true and == false checks?else, no final if.Related puzzles: