Difference between revisions of "Branch"

From APL Wiki
Jump to navigation Jump to search
(Created page with "{{Built-in|Branch|→}} is a primitive monadic function which provides a way to control execution flow in an APL programs. It is equivalent to GOTO...")
 
Line 28: Line 28:
 
<source lang=apl>
 
<source lang=apl>
 
       ⍝ While-Do construct
 
       ⍝ While-Do construct
       While:→(~B)/Done
+
       While: →(~B)/Done
 
       S1
 
       S1
 
       →While
 
       →While
Line 35: Line 35:
 
<source lang=apl>
 
<source lang=apl>
 
       ⍝ Repeat-Until construct
 
       ⍝ Repeat-Until construct
       Repeat:S2
+
       Repeat: S2
 
       →(~B)/Repeat
 
       →(~B)/Repeat
 
</source>
 
</source>
 +
Note that <source inline lang=apl>Else</source>, <source inline lang=apl>End</source>, <source inline lang=apl>CaseN</source>, <source inline lang=apl>Next</source>, <source inline lang=apl>While</source>, <source inline lang=apl>Done</source>, <source inline lang=apl>Repeat</source> in the examples above are all user-defined labels rather than keywords.
  
 
==External links==
 
==External links==

Revision as of 06:53, 27 July 2020

Branch () is a 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.

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