Vensim Help

 Navigation: Reference Guide > Functions > Logical Functions IF THEN ELSE(cond, tval, fval) Traditional IF-THEN-ELSE Statement

Returns first value (tval) if condition (cond) is true; second value (fval) if condition is false.   cond must be a Boolean expression or an expression or variable that can be interpreted as Boolean (i.e., taking a value of 0 or 1).  Only the value returned is evaluated, so the other value could be an expression that would lead to an error.

Units: IF THEN ELSE( dimensionless, Funits, units) --> units

Note that expressions such as (a>b) require that a and b have the same dimension and the resulting expression is considered to be dimensionless

Examples

IF THEN ELSE( 1.0<2.0, 3.0, 4.0 )

is equal to 3.0.

IF THEN ELSE( 1.0>2.0, 3.0, 4.0 )

is equal to 4.0.

IF THEN ELSE( X = 0.0, 1.0, 1.0 / X )

is equal to 1/X unless X is 0.0 when it is equal to 1.0.  If X is 0.0, Vensim will not try to compute 1/X and there will be no error.

Sample model: IF THEN ELSE + AND OR NOT.mdl in FunctionExamples