IFn functions

An IFn function takes an argument expression (Arg) and checks in which of predefined value intervals [–Е1; Е1Е2; Е2Е3, ... ; ЕnЕn+1; Еn+1] it falls. It then returns the result value [R1, R2, ..., Rn+2] from a predefined set of results that corresponds to the respective value interval. That is, R2 is returned if Е1 < Arg ≤ Е2.

Function pattern

The IFn function pattern may have two situations:

Result values match value intervals

In this case, IFn functions have:

The pattern of an IFn function is as follows:

IFn (Arg, E1, E2, E3 ..., En+1, R1, R2, R3, ..., Rn+2) (Here result values are entered for all predefined value intervals.)

In visual terms, this is shown in the following picture:

IF1 function: IF1(Arg, E1, E2, R1, R2, R3)
IF3 function: IF3(Arg, E1, E2, E3, E4, R1, R2, R3, R4, R5)

Consider the following example:

A=IF1(Arg, 3, 7, 10, 15, 20)

In the above case:

FOR A IS
Arg = 3 10
3 < Arg ≤ 7 15
7 < Arg 20

No result values for endmost value intervals

In this case IFn functions have:

NOTE: For the first and last value intervals, the program returns zero.

The pattern of an IFn function is as follows:

IFn (Arg, E1, E2, E3 ..., En+1, R1, R2, R3, ..., Rn) (Here, no result values are entered for the first and the last value intervals.)

Application

IFn functions are appropriate when parameters depend on other parameter — for example, we can create a dependence between the length of a box and the width of the glue flap. Consider the following example:

We have a regular rectangular box with a parameter A for the length of the body and a parameter GL for the glue flap width:

WHEN GL Should Take
A ≤ 100 10
100 < A < 200 15
A > 200 20

GL will take the values from the function IF1(A, 100, 200, 10, 15, 20), which we enter in its expression.