I wrote:

> It would be better writing a global handler to mimic the VBasic's
> inline if (iif(...)).
> 
> on iif (c, e1, e2)
>   if c the return e1
>   else return e2
> end
> 
> So you would simply have:
> return score / iif(total, total, 0)

Oops! Take a simple look and see it can't work. A yawn-mistake :~)
 
> (This one: return iif(total, score/total, 0) would fail because
> score/total is ever evaluated, so a divide by zero error occurs)

IMHO this ends the question. AFAIK, in most common languages, the conditional operators
(or functions) evaluate their on-line expressions in advance. So they can't help,
per-se, when problems due to divide by zero errors are pending. In the case the
regular "if... then... else... end if" statements are the best (cleanest and fastest)
solution.

The exception is the conditional operator (ternary operator) of CPP:
logical-OR-expression ? expression : conditional-expression
Note that either expression or conditional-expression is evaluated, but not both. So:
return (total) ? score / total : 0

Using iif() would ever be possible though. Eg:

-- Welcome to Director --
score = 2.0
total = 10.0
put score / iif(total, total, 1) - iif(total, 0, score)
-- 0.2000

score = 2.0
total = 0.0
put score / iif(total, total, 1) - iif(total, 0, score)
-- 0.0000

But only for love of complexities.

---
Care.
My above home made Lingo iif() works with integers. If a floating number is passed
for c, the line "if c the return e1" should be changed to "if c > 0 then return e1"
(this works both for floats and integers), otherwise Director issues an
"Integer expected" runtime error.

HTH, 

Franco

IFC Programming Consultant
http://www.chnexus.com/main.htm
Private mailto:[EMAIL PROTECTED] | [EMAIL PROTECTED]

[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to