>> << Ndx Usr Pri Phr Dic Rel Voc !: wd Help Dictionary

if.

    if. T do. B end.
    if. T do. B else. B1 end.
    if. T do. B elseif. T1 do. elseif. T2 do. B2 end.

The last sentence executed in a`T` block is tested for a non-zero value in its leading atom, determining whether the`B` block after the`do.` or the rest of the sentence is executed. An empty`T` block result or an omitted`T` block tests true.
See also the`select.` control structure.

For example:

    plus=: 4 : 0                  Addition on non-negative integers
     if. y. do. >: x. plus <: y. else. x. end.
    )

       plus"0/~ i.5
    0 1 2 3 4
    1 2 3 4 5
    2 3 4 5 6
    3 4 5 6 7
    4 5 6 7 8

    sel=: 1 : 'x. # ['

    quicksort=: 3 : 0
     if. 1 >: #y. do. y.
     else.
      (quicksort y.<sel e),(y.=sel e),quicksort y.>sel e=.y.{~?#y.
     end.
    )

       quicksort 15 2 9 10 4 0 13 13 18 7
    0 2 4 7 9 10 13 13 15 18

    test=: 3 : 0
     if.     0<y. do. 'positive'
     elseif. 0>y. do. 'negative'
     elseif.      do. 'zero'
     end.
    )

       test&.> 5 _2.71828 0
    +--------+--------+----+
    |positive|negative|zero|
    +--------+--------+----+

       test&.> '' ; 0 1 _2 ; _3 9
    +--------+----+--------+
    |positive|zero|negative|
    +--------+----+--------+

>> << Ndx Usr Pri Phr Dic Rel Voc !: wd Help Dictionary