Branch: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
mNo edit summary
Line 1: Line 1:
{{Built-in|Branch|→}} is a [[Primitive function|primitive]] [[monadic function]] which provides a way to control execution flow in an APL programs. It is equivalent to GOTO statement in other programming languages.
{{Built-in|Branch|→}} is a [[Primitive function|primitive]] [[monadic function]] which provides a way to control execution flow in an APL program. It is equivalent to GOTO statement in other programming languages.


It appeared in early versions of APL. In some APL dialects it was superseded by the more modern [[control structure]]s.
It appeared in early versions of APL. In some APL dialects it was superseded by the more modern [[control structure]]s.

Revision as of 07:37, 27 July 2020

Branch () is a primitive monadic function which provides a way to control execution flow in an APL program. It is equivalent to GOTO statement in other programming languages.

It appeared in early versions of APL. In some APL dialects it was superseded by the more modern control structures.

Examples

Branch function can be used to implement structured programming constructs without the use of special keywords:[1]

      ⍝ If-Then-Else construct
      →(~B)/Else
       S1
       →End
      Else:
       S2
      End:
      ⍝ Select construct
      →(Case1, Case2, Case3, Case4)[i]
      Case1: S1
       →Next
      Case2: S2
       →Next
      Case3: S3
       →Next
      Case4: S4
      Next:
      ⍝ While-Do construct
      While: →(~B)/Done
       S1
       →While
      Done:
      ⍝ Repeat-Until construct
      Repeat: S2
       →(~B)/Repeat

Note that Else, End, CaseN, Next, While, Done, Repeat in the examples above are all user-defined labels rather than keywords.

External links

Tutorials

Documentation

References