Rewrite of if else logic

I want to rewrite this peice of code below, because if the condition is true then nothing is done. Which is what the does is supposed
     to do, but I don't like the idea of nothing being done inside of the braces. So I have come up with two alternative pieces of code, marked as Question 1 and 2 below. Can someone validate my rewritten code logic that I labeled as Question 1 and 2 below?
                      // Here is the old code :
                      if (GamePlayer[2].hasJumped == true && iterator == 2)
                            {
                        // do nothing
                            }
                            else
                            {
                                GamePlayer[iterator].Processed = true;
                            }

Question 1:

So would the following new code rewrite be correct :

                      if (!(GamePlayer[2].hasJumped == true && iterator == 2))
                            {
                               GamePlayer[iterator].Processed = true;
                            }

Or also would this be correct as well:
Question 2:

                      if (GamePlayer[2].hasJumped == false || iterator != 2)
                            {
                               GamePlayer[iterator].Processed = true;
                            }
LVL 2
brgdotnetcontractorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robert SchuttSoftware EngineerCommented:
Let me start by saying that having an empty code block can be valid in terms of readability/maintainability, maybe just have a more meaningful comment describing why in that case nothing is done.

If you can't think of a more meaningful description then the first transition can also be the best way to code if the way a human would read that condition makes sense in that form as how they would think about that particular situation taking place, and would still makes sense thinking about it as "not  that particular situation". Remember, the computer will understand either way but it may be far more difficult to read for a human when normalized like you seem to desire.

That being said, the second transition is also correct as you can see here: https://www.wolframalpha.com/input/?i=!%28P+||+Q%29

Boolean logic has similar normalization rules like multiplication: (a + b) * x = a * x + b * x but with not  there is this interesting situation where it flips between or/and. You can verify this by looking at the truth tables:
a AND b

      |   a   |
      +---+---+
      | F | T |
--+---+---+---+
  | F | F | F |
b +---+---+---+
  | T | F | T |
--+---+---+---+

=======================
!(a AND b)

      |   a   |
      +---+---+
      | F | T |
--+---+---+---+
  | F | T | T |
b +---+---+---+
  | T | T | F |
--+---+---+---+

=======================
!a OR !b

      |   a   |
      +---+---+
      | F | T |
--+---+---+---+
  | F | T | T |
b +---+---+---+
  | T | T | F |
--+---+---+---+

Open in new window

or in words: the AND operation is only true when both  expressions are true. Because you only want the else part you put a NOT around the entire expression; that expression is true unless  both expressions are true. And finally the normalized expression shows the same table as the previous one, that could be described as: a or b needs to be false (or both).

Or in a slightly different form:
truth table

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
käµfm³d 👽Commented:
having an empty code block can be valid in terms of readability/maintainability
I think I'll disagree...for the majority. It should be exceedingly rare that you ever have an empty code block. I think it's more plausible that you should refactor your code in such a way that the empty block is not needed. In the above, I would advocate that writing the code without the empty block would be more readable.

Now, to get all computer-sciencey on you, keep in mind DeMorgan's laws. Basically, what they say is that when you have a certain set of boolean conditions, you can get the opposite of that condition by negating each condition (i.e. turning each true condition to a false condition, and each false condition to a true condition) and using the opposition conditional operator (i.e. turn ANDs into ORs and ORs into ANDs).

You can see this in action in your second snippet above. Whereas you originally had "hasJumped" compared to true, you changed it to false, and whereas you had "iterator" compared equal to 2, you changed it to not equal. Then you changed your && to a ||.
AndyAinscowFreelance programmer / ConsultantCommented:
In simple english.
You have this
if (GamePlayer[2].hasJumped == true && iterator == 2)
                            {
                        // do nothing
                            }
                            else
                            {
                                GamePlayer[iterator].Processed = true;
                            }

Open in new window


which if you changed to this is the same
if( ! (GamePlayer[2].hasJumped == true && iterator == 2) )
                            {
                                GamePlayer[iterator].Processed = true;
                            }

Open in new window


note the !
That means not and as the other experts have explained the not swaps a true to false or vice versa.  (Also the complete condition for the if statement is enclosed in brackets)
brgdotnetcontractorAuthor Commented:
Thanks Guys,

I kind of like the idea of the empty code block. Having gone through many code reviews, they would have not allowed for that. But hey, it's my party and I will cry if I want to right? In other words, it's my project and I'll do what I want to. Thanks you all
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.