Symbol Goto: Difference between revisions

From NARS2000
Jump to navigationJump to search
Line 9: Line 9:


===Conditional branch===
===Conditional branch===
The value to the right of the arrow is a boolean expression surrounded by parentheses, followed by the line number to transfer to if the expression is true.
The value to the right of the arrow is a boolean expression or non-negative number surrounded by parentheses, followed by a slash symbol and the line number to transfer to if the expression is true for a boolean expression or nonzero for a numeric value. A DOMAIN ERROR occurs if the numeric value is negative. In the following line 5 of a function:
:<tt> [5] {rightarrow}(A{lessthan}1)/22</tt>
Will branch to line 22 of the function if the value of A is less than 1. Execution would continue on line 6 if A was 1 or more.


===Unconditional branch===
===Unconditional branch===

Revision as of 17:08, 11 September 2015

→ — Branch to a line in a function — Keystroke ALT+] — Character 8594 or 0x2192

APLKB-Goto.png

Alternate Names

This symbol is also known as right arrow or APL text symbol {rightarrow}.

Usage

The goto symbol may be used as a conditional branch (branch based on a comparison) or an unconditional branch, or it may be used to exit a function. It is most often used in a function to transfer control, but can be used from the session manager to transfer to a line in a suspended function.

Conditional branch

The value to the right of the arrow is a boolean expression or non-negative number surrounded by parentheses, followed by a slash symbol and the line number to transfer to if the expression is true for a boolean expression or nonzero for a numeric value. A DOMAIN ERROR occurs if the numeric value is negative. In the following line 5 of a function:

[5] →(A<1)/22

Will branch to line 22 of the function if the value of A is less than 1. Execution would continue on line 6 if A was 1 or more.

Unconditional branch

The goto symbol is followed on the right either by the line number or a label. Execution continues in the function at that line (unless the line specified is 0, in which case the function exits.)

Exit Function

The goto symbol may be used to exit a function and return to the calling function (or return to the session manager if the function was called by the user typing its name) by using 0 as the line number to goto.

Examples

Exit Function

In the following example, function one calls function two, which exits part way through the function, returning to function 1.

∆one

[0] one
[1] 'This is one'
[2] two
[3] 'return to one from two'

∆two

[0] two
[1] 'This is two'
[2] →0
[3] 'Two Continues'

one

This is one
This is two
return to one from two


Another Example see: Control Structures - Branching Example


See Also
System Commands System Variables and Functions Operators


Keyboard
A+S
Alt ¨ ¯ < > × ÷
Sh ~ ! @ # $ % ^ & * ( ) _ +
Key ` 1 2 3 4 5 6 7 8 9 0 - =
A+S
Alt ? § π
Sh Q W E R T Y U I O P { } |
Key q w e r t y u i o p [ ] \
A+S
Alt
Sh A S D F G H J K L : "
Key a s d f g h j k l ; '
A+S χ
Alt
Sh Z X C V B N M < > ?
Key z x c v b n m , . /
{{#ifeq:{{{1}}}|4||title="match" style="border-width:thick; border-color:blue; background-color:yellow;"| {{#ifeq:{{{1}}}|7||title="iota" style="border-width:thick; border-color:blue; background-color:yellow;" | {{#ifeq:{{{1}}}|9||title="slash" style="border-width:thick; border-color:blue; background-color:yellow;" |/ {{#ifeq:{{{1}}}|11||title="diamond" style="border-width:thick; border-color:blue; background-color:yellow;" | {{#switch: {{{1}}}
NARS 2000 Lang
Tool
Bar

{{#ifeq:{{{1}}}|1||title="assign" style="border-width:thick; border-color:blue; background-color:yellow;" |

bgcolor=cyan title="assign" | }}

{{#ifeq:{{{1}}}|2||title="plus" style="border-width:thick; border-color:blue; background-color:yellow;" |+

- × ÷ * ! ? bgcolor=cyan title="plus" |+ - × ÷ * ! ? }}

{{#ifeq:{{{1}}}|3||title="mod" style="border-width:thick; border-color:blue; background-color:yellow;" ||

< = > bgcolor=cyan title="match" | < = > }}

{{#ifeq:{{{1}}}|5||title="down caret" style="border-width:thick; border-color:blue; background-color:yellow;" |

bgcolor=cyan title="down caret" | }}

{{#ifeq:{{{1}}}|6||title="take" style="border-width:thick; border-color:blue; background-color:yellow;" |

~ § π .. bgcolor=cyan title="iota" | ~ § π .. }}

{{#ifeq:{{{1}}}|8||title="comma" style="border-width:thick; border-color:blue; background-color:yellow;" |,

\ ¨ . bgcolor=cyan title="slash" |/ \ ¨ . }}

{{#ifeq:{{{1}}}|10||title="quotequad" style="border-width:thick; border-color:blue; background-color:yellow;" |

_ bgcolor=cyan title="diamond" | _ }}

{{#ifeq:{{{1}}}|12||title="neg" style="border-width:thick; border-color:blue; background-color:yellow;" |¯

title="neg" |¯
colspan=8 |Second Row i j k a b e g p r v x z colspan=8 |Second Row i j k a b e g p r v x z colspan=8 |Second Row i j k a b e g p r v x z colspan=6 |Second Row i j k i j k l g p r v x

}}

{{#ifeq:{{{1}}}|0| |[[Category:Mouse Group {{{1}}}|{{{2}}}]]}}


{{#ifeq:1|0| |}}