Jump anywhere: Difference between revisions

Content added Content deleted
m (→‎{{trans|Common Lisp}}: a tag correction)
No edit summary
Line 989: Line 989:
end.
end.
</syntaxhighlight>
</syntaxhighlight>

=={{header|EMal}}==
<syntaxhighlight lang="emal">
type JumpAnywhere
^|EMal has no goto statement, but supports exceptions.
|The following are the basic EMal jumps.
|^
fun sample = void by block
for int i = 1; i < 10; ++i
if i == 1 do continue end # jumps to next iteration when 'i' equals 1
writeLine("i = " + i)
if i > 4 do break end # exits the loop when 'i' exceeds 4
end
for int j = 1; j < 10; ++j
writeLine("j = " + j)
if j == 3 do return end # returns from the function when 'j' exceeds 3
end
end
sample()
type StateMachine
^|this code shows how to selectevely jump
|to simulate a state machine as decribed here:
|https://wiki.tcl-lang.org/page/A+tiny+state+machine
|Functions return the next state.
|^
int n = -1
Map stateMachine = int%fun[
0 => int by block
if Runtime.args.length == 1
n = when(n == -1, int!Runtime.args[0], 0)
else
n = ask(int, "hello - how often? ")
end
return when(n == 0, 2, 1)
end,
1 => int by block
if n == 0 do return 0 end
writeLine(n + " Hello")
n--
return 1
end,
2 => int by block
writeLine("Thank you, bye")
return -1
end]
int next = 0
for ever
next = stateMachine[next]()
if next == -1 do break end
end
</syntaxhighlight>
{{out}}
<pre>
./JumpAnywhere.emal 2
i = 2
i = 3
i = 4
i = 5
j = 1
j = 2
j = 3
2 Hello
1 Hello
Thank you, bye
</pre>

=={{header|Erlang}}==
=={{header|Erlang}}==
Jumps are limited to [[Exceptions]].
Jumps are limited to [[Exceptions]].