Control structure

From APL Wiki
Jump to navigation Jump to search

Some modern versions of APL include a set of keywords for controlling flow of execution. Such keywords allow programmers to create control structures which are commonly used in procedural programming languages.


Dyalog APL has a rich set of flow control keywords, including :If, :While, :Repeat, :For (with the supplementary control words :In and :InEach), :Select, :With, :Trap, :Hold and :Disposable. The use of control structures defined by these keywords is only allowed in defined functions.

For example, a function implementing the Trabb Pardo–Knuth algorithm using control structures:

  S,⍎{  ()}'Please, enter 11 numbers: '
  :For i a :InEach (⌽⍳≢S)(S)
      :If 400<yf(a)
          'Too large: ',⍕i

External links