if

From The K Language Wiki
If
$[c;t;[c1..]f]

if or cond is the main form of conditional evaluation in K.

If is special, because its arguments are not evaluated until their respective condition is evaluated. This allows for side effects to be caused conditionally by an if statement. Multiple conditions can be given by specifying more pairs of conditions c and expressions e like $[c1;e1;c2;e2;c3;e3;...].[1]

The return value of multi argument $ is the one which is after the first condition satisfied. If none of the conditions are satisfied, the last argument is returned.

 $[1;"true";false]
"true"
 $[0;"true";false]
value error
 $[0;"cond1";0;"cond2";1;"cond3";"cond4"]
"cond3"

References[edit]