You misunderstand, but maybe I didn't explain it very well \:\)

IIF only returns values. However, the values may be derived from any source including complex expressions, the return values of functions, object methods and so-on.

The problem is the way that the parser / runtime resolves the symbols. Basically the expressions in the IIF() statement are resolved to simple values *before* the conditional part is evaluated.

Take one of the examples:
 Code:
$Var1=10
$Var2=2
$Action="Multiply"
"Result of "+$Var1+" "+$Action+" "+$Var2+" is "+Iif($Action="Multiply",doMult($Var1,$Var2),doDiv($Var1,$Var2))+@CRLF


The IIf() will resolve something like this:
  1. Iif($Action="Multiply",doMult($Var1,$Var2),doDiv($Var1,$Var2))
  2. Iif("Multiply"="Multiply",doMult(10,2),doDiv(10,2))
  3. Iif("Multiply"="Multiply",20,5)
  4. Iif(1,20,5)
  5. 20


That's not necessarily the exact process, but it's close enough to see what the problem is. What is clear is that the evaluation of the conditional part is the last thing that happens.

This causes two problems.
First, both the true and false expressions have been evaluated - in this case both functions have been called.
Second, it means that you cannot use *any* expression which might be invalid even if it is not going to be used. This includes simple variables as well as more complex expressions.

Here is a good example of how easy it is to fall into the trap. Let's say that you want to assign a default when a value has not been passed on the command line:
 Code:
$=SetOption("Explicit","ON")
$=IIf(IsDeclared($SERVER),$SERVER,".")


This looks fine - if the user has passed "$SERVER" on the command line then it is used. If the user has not specified $SERVER then the local computer "." is used instead.

The problem is that $SERVER is evaluated before the conditional, so the script will abort with an "undefined variable" error if the user has not passed the variable on the command line.

IMO IIf() in KiXtart is an accident waiting to happen, and is only really useful for golf. My recommendation is to avoid it in production work.