iif evaluates both conditions?

Discuss any general programming issues here
Post Reply
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

iif evaluates both conditions?

Post by lazi »

Hi!

Just figured out that iif can't be used to avoid division by zero errors.

a = iif ( b=0, 0, 5/b) ; fails when b is zero

It's a shame that all of the results are evaluating apart from the result of the condition.
I think it is a Lua "feature", but tested similar method on php and behaves just like Hollywood.

I don't think Andreas would change this, so I just wanted to remind you.

Bye!
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: iif evaluates both conditions?

Post by airsoftsoftwair »

This is already mentioned in the IIf() documentation with exactly the same example :)
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

Re: iif evaluates both conditions?

Post by lazi »

Hehe, that's correct. :oops:

"The person who doesn't read, has no advantage over those who can't read!"

To be honest since I use the great Cubic-IDE add-on I visiting less the also great guide. However it is a mistake that this topic clearly proves.
Post Reply