Hello!
If you got crazy stuff going on, it might help you to use a
flag to
monitor the checks you are doing.
So you can do it one step at the time...
- boolean wowIReallyShouldDoThisNow = false;
- // do the checks
- if (!A) {
- wowIReallyShouldDoThisNow = true;
- println ("ok, it's !A now.");
- }
- if ( !(!A && B) ) {
- wowIReallyShouldDoThisNow = true;
- println ("ok, this is !(!A && B) here... A is " + A + " and B is " + B + ".");
- }
- // checks are all done
- // finally evaluate result
- if (wowIReallyShouldDoThisNow) {
- // finally do it
- }
Please note that in this way
wowIReallyShouldDoThisNow is false at startup and can only become
true - not false again.
Since you do it step by step, the steps are connected by a logical OR.
So in hard parts this might be easier to program and to read, especially if you have to do 3 or 4 tests...
Greetings, Chrisir
P.S.
Also, when you need e.g. a for-loop instead of (!A) you can use a function that returns boolean (when you e.g. need a for-loop to check each member of an array and return true if all members have a certain value):
- If (allEnemyCowsAreFinallyRed()) {
- wowIReallyShouldDoThisNow = true;
- println ("All enemy cows are red.");
- }
With a function allEnemyCowsAreFinallyRed() containing a for-loop over the array of cows.