IIF() seems to be executing both returnvalues befor returning one of them and this can cause array out of bounds errors.

Code:

$l = -1
$a = 1,2,3,4,5
? iif($l>-1,$a[$l],$l)



if $l is equal to -1 then the IFF() statment should return the false return value... but it is throwing an array out of bounds error because it is evaluating the array value, but you cant have an array value of -1.

you can see the proper behavio by

Code:

? iif($l>-1,"true","false")



that code causes no errors, and returns "false" One would think that the first IIF line of code, would just return the "false" returnvalue with out executing the "true" returnvalue"

Am i mistaken in the behavior of IIF()?

Bryce