Anonymous user
Flow-control structures: Difference between revisions
m
{{out}} / -Category:Scala Implementations
(Add Nimrod) |
m ({{out}} / -Category:Scala Implementations) |
||
Line 1:
{{Task|Control Structures}}
{{Control Structures}}
In this task, we document common flow-control structures.
One common example of a flow-control structure is the <tt>goto</tt> construct.
Note that [[Conditional Structures]] and [[Iteration|Loop Structures]]
have their own articles/categories.
=={{header|6502 Assembly}}==
Line 130 ⟶ 133:
$xz","3z","3z","2z-d$, previous,
$xd.n(real width - 1)d$, current / previous)).</lang>
{{out}}
<pre>
Exited when: i=13, j=53
Line 191 ⟶ 194:
& out$Hi!
& !LOOP</lang>
{{out}}
<pre>Hi!
Hi again!
Line 1,026 ⟶ 1,029:
{Show {SearchOne Stupid}}</lang>
{{out}}
<pre>
choosing 8
Line 1,034 ⟶ 1,037:
=={{header|PARI/GP}}==
Flow control structures include function calling and returning, <code>error</code>/<code>trap</code>, <code>next</code>/<code>break</code>, <code>alarm</code>,
and the various loops.
=={{header|Pascal}}==
Line 1,101 ⟶ 1,105:
echo 'Bar';
?></lang>
{{out}}
<pre>Bar</pre>
Line 1,419 ⟶ 1,423:
# End of 'try' block...</lang>
Note: Prior to version 2.5 a ''try:'' statement could contain either series of ''except:'' clauses '''or''' a ''finally:'' clause but '''not both.'''
It was thus necessary to nest the exception handling in an enclosing ''try:''...''finally:'' loop like so:
<lang python>try:
Line 1,820 ⟶ 1,825:
say; say "Moral: don't do that."
exit 13</lang>
{{out}}
<pre>
──────────────────────error!─────────────────────────
Line 1,958 ⟶ 1,963:
say; say "Moral: shouldn't do that."
</lang>
{{out}}
<pre>
───────────────────────────error!─────────────────────────────────
Line 2,069 ⟶ 2,074:
=={{header|Scala}}==
{{libheader|Scala}}
<lang Scala>import Goto._
Line 2,101 ⟶ 2,105:
=== after ===
The <tt>after</tt> facility can be used to execute some code
at some future time asynchronously, like this
<lang tcl>after 1000 {myroutine x}</lang>
which will call "<tt>myroutine</tt>" with parameter "<tt>x</tt>" 1000ms from 'now';
no matter what other code might be running at the time (i.e. "<tt>after</tt>"; schedules the execution, then returns and continues program flow with the following code).
The scheduled task can be removed from the scheduler for example with
Line 2,113 ⟶ 2,119:
(other ways are possible).
The correct way to schedule some regularly recurring task in TCL
is to incorporate a self-scheduling at the end of the routine.
For example the following will produce a clock
whose display is updated once a second:
<lang tcl>package require Tk
Line 2,220 ⟶ 2,229:
=== Return value / Exit Function ===
This shows the classical and modern syntax for exiting a function early.
There is an implied variable with the same name as the function.
This variable is write-only.
<lang vbnet>Function Foo3()
|