Jump anywhere: Difference between revisions

→‎{{header|Scala}}: Removed a non-responsive and strident non-answer. Added SNOBOL4 example.
(→‎{{header|TXR}}: New section.)
(→‎{{header|Scala}}: Removed a non-responsive and strident non-answer. Added SNOBOL4 example.)
Line 2,855:
This code uses the Continuation object <code>c</code> to jump to the top of the loop. For the first iteration, <code>callcc</code> creates <code>c</code> and returns <code>[c, 1]</code>. For later iterations, <code>callcc</code> returns <code>[c, i + 1]</code>. For the last iteration, <code>callcc</code> returns <code>nil</code> to break the loop.
 
=={{header|ScalaSNOBOL4}}==
 
Goto's are in the European programmer community [http://en.wikipedia.org/wiki/Considered_harmful considered harmful]. They are error-prune and not essential. A good programmer would stay away from that. Scala is not equipped with goto's.
Branches are the only kind of control structure in SNOBOL4. They come in three flavours (and one compound one):
 
* <code>:(LABEL_UNCONDITIONAL)</code>
* <code>:S(LABEL_ON_SUCCESS)</code>
* <code>:F(LABEL_ON_FAILURE)</code>
* <code>:S(LABEL_ON_SUCCESS)F(LABEL_ON_FAILURE)</code> or <code>:F(LABEL_ON_FAILURE)S(LABEL_ON_SUCCESS)</code>
 
<syntaxhighlight lang="snobol4">
* Demonstrate an unconditional branch.
OUTPUT = "Unconditional branch." :(SKIP1)
OUTPUT = "This will not display."
 
* Demonstrate a branch on success.
SKIP1 v = 1
SKIP1.A gt(v, 5) :S(SKIP2)
OUTPUT = "Iteration A" v
v = v + 1 :(SKIP1.A)
 
* Demonstrate a branch on failure.
SKIP2 v = 1
SKIP2.A le(v, 5) :F(SKIP3)
OUTPUT = "Iteration B" v
v = v + 1 :(SKIP2.A)
 
* Demonstrate a combined branch.
* Demonstrate also an indirect branch.
SKIP3 v = 0
label = "SKIP3.A"
SKIP3.A v = v + 1
le(v, 5) :S(SKIP3.B)F(EXIT)
SKIP3.B OUTPUT = "Iteration C" v :($label)
 
EXIT OUTPUT = "Goodbye"
 
END
</syntaxhighlight>
 
{{Out}}
 
<pre>
Unconditional branch.
Iteration A1
Iteration A2
Iteration A3
Iteration A4
Iteration A5
Iteration B1
Iteration B2
Iteration B3
Iteration B4
Iteration B5
Iteration C1
Iteration C2
Iteration C3
Iteration C4
Iteration C5
Goodbye
</pre>
 
=={{header|SPL}}==
34

edits