Public Group

if () statement question

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

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  typo [/edit]

Share on other sites
]
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 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 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

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 10
• 11
• 13
• 9
• Forum Statistics

• Total Topics
634094
• Total Posts
3015469
×