The purpose of in-line select (or, alternatively, "case" or "switch", depending on the language) and in-line if is to avoid having to write custom procedures, create arrays, etc., where you simply want to say "Based on the contents of this variable (or logical evaluation), return this value." For instance, say you wanted to return the name of the day in Spanish. Yes, you could write an array, or a multi-line If comparison, etc., but it would be a lot easier to just have DayName = Select(DOW, "Domingo", "Lunes", "Martes", "Miercoles", etc.)
As I mentioned, I have written a set of "in-line if" functions, but it requires a separate one for each data type:
IifStr() String - in-line if returns first string if condition is true, else second
IifChar() Char - in-line if returns first character if condition is true, else second (etc.) IifDate() IifTime() IifInt() IifDouble() IifMoney()
FoxPro has both and it makes programming much easier. Often something can be done with a single line of code interactively that requires an entire subroutine in most other languages--often just because they lack an in-line if or an in-line select function, so a full-blown CASE A ... CASE B ... DEFAULT ... END CASE structure has to be used.
Whether it is in-line if or in-line select, they shouldn't be just for strings, e.g., Bonus = Select(YearsOfService, 200, 500, 1000, 1500) or whatever.
... And for that example, you would probably want to nest an in-line if so that:
Bonus = Select(iif(YearsOfService < 4, YearsOfService, 4), 200, 500, 1000, 1500)
|