java - Simplify boolean expression -
this question has answer here:
- boolean checking in if() 10 answers
i have bit of code , eclipse telling me boolean expressions can simplified.
knightturn == true && occupied ==true
and
knightturn == true
both boolean knightturn , boolean occupied set false earlier in code.
boolean knightturn=false boolean occupied=false @tags({"passed"}) public void passed () { final int x = 50; if (knightturn == true && occupied == true) { (int i=0; i<x; i++) { standknight.moveavatar(i, 0); avatareditor.refresh(); i++; } occupied = false; } } @tags({"failed"}) public void failed () { final int x = 35; if (knightturn == true) { (int i=0; i<x; i++) { standknight.moveavatar(i, i/2); avatareditor.refresh(); i++; } occupied = false; }
the code still runs should, how tidy bit , make simpler?
if (knightturn == true && occupied == true)
can written as
if (knightturn && occupied)
this reduces possibility of making mistakes these
if (knightturn = true)
Comments
Post a Comment