It works similar to "IIf" function of Visual Basic (as you can read there, "IIf" stands for "Internal If"), NVL2() function of PL/SQL and the ternary operator of C (<cond> ? <if true> : <if false>;). This approach is very convenient - why not to have it in PB? It helps to keep scripts shorter by avoiding the if...else construction - each use of iif() removes 4 extra lines from the script. That's how the fragment would be looking like without iif():
if lc_sex = "M" then ls_greeting = "Mr" else ls_greeting = "Ms" end if
CAUTION! If you pass an expression as the 2nd or 3rd argument, that expression is evaluated before being sent to the function (no matter what the result of the Boolean expression is), so DON'T USE iif() as a protection, i.e. to prevent things like zero divide or reading from a not-existing row in a DataWindow:
Save the file iif.srf on your hard disk and import it into your application. The function is overloaded for the following datatypes: string, long, decimal, date, time, datetime, powerobject. To see the overloads, open the function in the "Edit Source" mode. If you are surprised that a global functions is overloaded then read here.