We help IT Professionals succeed at work.
Get Started

Rewrite of if else logic

brgdotnet asked
Last Modified: 2015-04-08
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
                                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;
Watch Question
Software Engineer
This problem has been solved!
Unlock 3 Answers and 4 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE