Control structure: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
|||
Line 24: | Line 24: | ||
* Bernard Legrand. [https://www.dyalog.com/uploads/documents/MasteringDyalogAPL.pdf#page=189 Mastering Dyalog APL (page 189)]. [[Dyalog Ltd]]. November 2009. | * Bernard Legrand. [https://www.dyalog.com/uploads/documents/MasteringDyalogAPL.pdf#page=189 Mastering Dyalog APL (page 189)]. [[Dyalog Ltd]]. November 2009. | ||
=== Documentation === | === Documentation === | ||
* [https://help.dyalog.com/latest/#Language/Control%20Structures/Control%20Structures%20Introduction.htm#ControlStructures Dyalog | * [https://help.dyalog.com/latest/#Language/Control%20Structures/Control%20Structures%20Introduction.htm#ControlStructures Dyalog] | ||
* [http://microapl.com/apl_help/ch_020_010_047.htm APLX] | |||
[[Category:APL syntax]] | [[Category:APL syntax]] |
Revision as of 11:24, 19 July 2020
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.
Example
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:
∇ {res}←trabb;f;S;i;a;y f←{(0.5*⍨|⍵)+5×⍵*3} S←,⍎{⍞←⍵ ⋄ (≢⍵)↓⍞}'Please, enter 11 numbers: ' :For i a :InEach (⌽⍳≢S)(⌽S) :If 400<y←f(a) ⎕←'Too large: ',⍕i :Else ⎕←i,y :EndIf :EndFor ∇
External links
Tutorials
- APL Cultivation: Control structures
- Bernard Legrand. Mastering Dyalog APL (page 189). Dyalog Ltd. November 2009.