IF

Purpose:

Evaluates a conditional expression. If the conditional expression is TRUE (non-zero), the trueExpr is evaluated, if the conditional expression is FALSE (zero), the optional falseExpr is evaluated. trueExpr and falseExpr can be any valid expression.

Syntax:

IF(cond, trueExpr, falseExpr)

 

cond

-

Any expression resolving to a number.

trueExpr

-

Expression to evaluate if condition is TRUE (non-zero).

falseExpr

-

Optional. Expression to evaluate if condition is FALSE (zero)

 

Alternate Syntax:

SPL compound syntax:

 

if (expr) statements

if (expr) statements1 else statements2

 

expr

-

Any expression resolving to a number.

statements

-

One or more valid expressions separated by semicolons.

Returns:

The result of evaluating trueExpr or falseExpr.

Example:

if(max(W1) > max(W2), gsin(100, .01, 1.0), grand(200, 1.0))

 

Functional form. If the maximum value of W1 is greater than the maximum value of W2, then generate a sine wave in the current Window. If not, generate a random series in the current Window.

Example:

if (max(W1) > max(W2))
{
    gsin(100, .01, 1.0);
}
else
{
    grand(200, 1.0);
}

 

SPL form. Operates the same as above.

Remarks:

The compound IF-ELSE statement applies to SPL files.

 

Versions of DADiSP prior to 3.0 required quotes around trueExpr and falseExpr. For the sake of backward compatibility, DADiSP accepts the true and false expressions with or without quotes. However, if possible, do not include quotes around these expressions as future versions of DADiSP may not support this syntax.

 

The C/C++ style ternary conditional statement is also supported. For example, the statement:

 

a = (b > a) ? b : b * b;

 

is equivalent to:

 

if (b > a)
{
    a = b;
}
else
{
    a = b * b;
}

 

See SWITCH to transfer control to one of several statements based on a number or string.

See Also:

SPL: Series Processing Language

SWITCH

WHILE