3.5.1.7.11 Ifs

Description

Minimum Origin Version Required: 2019 SR0

This function is used to evaluate a value to multiple conditions, and return the corresponding value when the first TRUE condition is met. Up to 40 conditions can be supported. It is the equivalent of nested If function but easier to read, especially when there are many conditions.

Note: to set a default result, you will need to use 1 instead of TRUE for LabTalk compability. For example,

Ifs(A>0.5,"Large",A<0.3,"Small",1,"Other")$

it means, if values in col(A) is larger than 0.5, return Large, if smaller than 0.3, returns Small, the rest in between will return Other.

Syntax

double Ifs(string con1, double d1[, string con2, double d2,]...[,string con40,double d40])
string Ifs(string con1, string str1$[, string con2, string str2$]...[,string con40, string str40$])$

Parameters

conn

The expression of nth condition. Up to 40 conditions can be supported.

dn, strn

The returned value when the nth condition is True. It can be numeric or text. If text value, must be inclosed in double quotes ("").

Return

Return

Example

Ex1

IF value in col(A) is larger than 0.5, returns Large, smaller than 0.3, returns Small, otherwise returns Median.

  1. Create a new Workbook. Fill col(A) with some random number.
  2. In the F(x) header row of col(B) enter formula
    Ifs(A>0.5,"Large",A<0.3,"Small",1,"Median")$

Ex2

newbook;
patternT irng:=col(A) text:="Apple Boy Cat" mode:=random;
csetvalue col:=col(B) formula:="ifs(A$=="Apple","Fruit",A$=="Boy","People",A$=="Cat","Animal")$";

See Also

If, Switch