Formulas 7. Control structures

if ... then ... else ... fi

You can use conditional expressions in all formulas. For example,

    3 * if 52% * 3908 > 2000 then 5 else 6 fi

evaluates to 15. Instead of fi, you can also use endif.

Another example: you can clip the absolute amplitude of a Sound to 0.5 by supplying the following formula:

    if abs(self)>0.5 then if self>0 then 0.5 else -0.5 fi else self fi

The semicolon

The semicolon ends the evaluation of the formula. This can be convenient if you do not want to overwrite a long formula in your text field: the formula

    800;sqrt(2)*sin(2*pi*103*0.5)+10^(-40/20)*randomGauss(0,1)

evaluates to 800.

Links to this page


© ppgb 20031228