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 ((frac == 1 || ineGrang() && i != he && ibost() && ihesm() <= 0) && ce) {
...
...
// Pretend there is lots of code here
...
...
} else {
sarden();
}
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 (!ce || (ihesm() >= 0 || !ibost() || i == he || !ineGrang()) && frac != 1) {
sarden();
} 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 (langal() && tiss < a) {
if (!ir && prahic() && vuon) {
if (vuon) {
return true;
}
if (erkde()) {
return true;
}
}
}
if (chong()) {
return true;
}
return false;
return chong() && ((erkde() || !ir && prahic()) && vuon || langal() && tiss < a);
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 (!chong()) {
if (!langal() && !vuon || !prahic() && !erkde() || ir && !erkde()) {
if (!prahic() && !erkde() || ir && !erkde()) {
if (!vuon) {
return false;
}
}
if (tiss > a) {
return false;
}
}
}
return true;
Simplify the following messy chain of conditionals:
if (ru < 6) {
fofa();
}
if (stis == true && ru > 6) {
stol();
}
if (es == true && ru > 6 && stis != true) {
phas();
} else if (bi == false && ru > 6 && stis != true && es != true) {
nimir();
} else if (euc == true && ru > 6 && stis != true && es != true && bi != false) {
deic();
}
if (ostu == true && ru > 6 && stis != true && es != true && bi != false && euc != true) {
elded();
}
{
if (ru < 6) {
fofa();
}
if (stis) {
stol();
}
if (es) {
phas();
}
if (!bi) {
nimir();
}
if (euc) {
deic();
}
if (ostu) {
elded();
}
}
Things to double-check in your solution:
== true and == false checks?else if, not just else.Related puzzles: