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 (!(pris() == er || lo >= 5 && id || ischa()) || ca != 3 && (hosm() && !cem || setcet()) || !axwe || i == 0 && uicmir() >= fliou()) {
...
...
// Pretend there is lots of code here
...
...
} else {
onga();
}
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 ((uicmir() <= fliou() || i != 0) && axwe && (!setcet() && (cem || !hosm()) || ca == 3) && (pris() == er || lo >= 5 && id || ischa())) {
onga();
} 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 (clah < sulPlocon() && oi == 2 && on && arde && !a || !assa || cilPhimp() || panco() >= em && arde && !a || !assa || cilPhimp() || pa && arde && !a || !assa || cilPhimp() || de && arde && !a || !assa || cilPhimp() || teasm() && arde && !a || !assa || cilPhimp()) {
if (!assa || cilPhimp()) {
if (!a) {
return true;
}
}
if (arde) {
return true;
}
if (!sa) {
return true;
}
}
return false;
return (!sa || clah < sulPlocon() && oi == 2 && on || panco() >= em || pa || de || teasm()) && arde && (!a || !assa || cilPhimp());
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 (!teasm() && !de && !pa && panco() <= em && !on && sa || oi != 2 && sa || clah > sulPlocon() && sa) {
if (!arde) {
if (a) {
return false;
}
if (assa) {
return false;
}
if (!cilPhimp()) {
return false;
}
}
}
return true;
Simplify the following messy chain of conditionals:
if ((haie != 0) == true) {
creou();
}
if (ia == true && (haie != 0) != true) {
oenQeciss();
} else if (biss == true && (haie != 0) != true && ia != true) {
iead();
}
if (re == false && (haie != 0) != true && ia != true && biss != true) {
egliss();
} else if (fa == ko && (haie != 0) != true && ia != true && biss != true && re != false) {
oorMocet();
} else if (dris == true && (haie != 0) != true && ia != true && biss != true && re != false && fa != ko) {
siios();
}
if ((ur != 3) == true && (haie != 0) != true && ia != true && biss != true && re != false && fa != ko && dris != true) {
dubes();
}
if (sor == false && (haie != 0) != true && ia != true && biss != true && re != false && fa != ko && dris != true && (ur != 3) != true) {
cimiad();
} else if (chra == true && (haie != 0) != true && ia != true && biss != true && re != false && fa != ko && dris != true && (ur != 3) != true && sor != false) {
haki();
}
if (chec == true && (haie != 0) != true && ia != true && biss != true && re != false && fa != ko && dris != true && (ur != 3) != true && sor != false && chra != true) {
falCus();
}
if (ul == true && (haie != 0) != true && ia != true && biss != true && re != false && fa != ko && dris != true && (ur != 3) != true && sor != false && chra != true && chec != true) {
skae();
}
{
if (haie != 0) {
creou();
}
if (ia) {
oenQeciss();
}
if (biss) {
iead();
}
if (!re) {
egliss();
}
if (fa == ko) {
oorMocet();
}
if (dris) {
siios();
}
if (ur != 3) {
dubes();
}
if (!sor) {
cimiad();
}
if (chra) {
haki();
}
if (chec) {
falCus();
}
if (ul) {
skae();
}
}
Things to double-check in your solution:
== true and == false checks?else if, not just else.Related puzzles: