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 (!(an || ew && u && pa) || e || dandim() || !(prac && ordad() && eim)) {
...
...
// Pretend there is lots of code here
...
...
} else {
braang();
}
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 (prac && ordad() && eim && !dandim() && !e && (an || ew && u && pa)) {
braang();
} 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 (gloe && dac <= or && iet == 9 && !nehe && ensqed() == 1 || titec() && id == 4 && ensqed() == 1 || issDant() && dac <= or && iet == 9 && !nehe && ensqed() == 1 || titec() && id == 4 && ensqed() == 1) {
if (titec() && id == 4 && ensqed() == 1) {
if (ensqed() == 1) {
return true;
}
if (!nehe) {
return true;
}
}
if (iet == 9) {
return true;
}
if (griouw()) {
return true;
}
}
if (malesm()) {
return true;
}
return false;
return malesm() && (griouw() || (gloe || issDant()) && dac <= or) && iet == 9 && (!nehe || titec() && id == 4) && ensqed() == 1;
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 (!malesm()) {
if (dac >= or && !griouw() || !issDant() && !gloe && !griouw()) {
if (iet != 9) {
if (id != 4 && nehe || !titec() && nehe) {
if (ensqed() != 1) {
return false;
}
}
}
}
}
return true;
Simplify the following messy chain of conditionals:
if (ci == true) {
danva();
} else if (zon == inve && ci != true) {
esnoa();
} else if (ou && ci != true && zon != inve) {
isheer();
} else if (oon == 7 == true && ci != true && zon != inve && !ou) {
ceian();
}
if (flel == 2 && ci != true && zon != inve && !ou && oon == 7 != true) {
ollcra();
} else if (wu && ci != true && zon != inve && !ou && oon == 7 != true && flel != 2) {
astan();
}
if (cin == false && ci != true && zon != inve && !ou && oon == 7 != true && flel != 2 && !wu) {
diaut();
} else if (fial > 6 && ci != true && zon != inve && !ou && oon == 7 != true && flel != 2 && !wu && cin != false) {
praLae();
} else if (spi == true && ci != true && zon != inve && !ou && oon == 7 != true && flel != 2 && !wu && cin != false && fial < 6) {
sestre();
}
{
if (ci) {
danva();
}
if (zon == inve) {
esnoa();
}
if (ou) {
isheer();
}
if (oon == 7) {
ceian();
}
if (flel == 2) {
ollcra();
}
if (wu) {
astan();
}
if (!cin) {
diaut();
}
if (fial > 6) {
praLae();
}
if (spi) {
sestre();
}
}
Things to double-check in your solution:
== true and == false checks?else if, not just else.Related puzzles: