Jump to content
  • Advertisement
Sign in to follow this  
derry

if () statement question

This topic is 4729 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ey ppl, I was wondering why this:
if ((Vakjes[j] != 0) && (Vakjes[j] == Vakjes[i+1][j] == Vakjes[i+2][j] == Vakjes[i+3][j]))

values: vakjes[j] = 1, vakjes[i+1][j] = 2, vakjes[i+2][j] = 1, vakjes[i+3][j] = 0
returns a TRUE if the values aren't equal (code is C++ btw) thnx for your time/help derry [edit] typo [/edit]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
]
T F
1 != 0 && 1 == 2 == 1 == 0
if ((Vakjes[j] != 0) && (Vakjes[j] == Vakjes[i+1][j] == Vakjes[i+2][j] == Vakjes[i+3][j]))

False.

Share this post


Link to post
Share on other sites
probably because what your'e testing is

((Vakjes[j] == Vakjes[i+1][j]) == Vakjes[i+2][j]) == Vakjes[i+3][j]

that evaluate to:

((1 == 2) == 1) == 0

that in turn is:

0 == 1 == 0

and since 0 != 1 that will be

0 == 0

which is true :D

I guess what you really ment to write was:

((Vakjes[j] == Vakjes[i+1][j]) && (Vakjes[i+1][j]) == Vakjes[i+2][j]) && (Vakjes[i+2][j] == Vakjes[i+3][j]))

Share this post


Link to post
Share on other sites
thnx for the quick reply, i thought about it myself aswell approximatly 1 min before you posted, and then i saw the comfoirmation here.
(i wonder why i spend an hour yesterday trying to figure it out lol)

thnx for the help, and it was indeed what i was looking for

derry

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!