Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
47
Task/Jump-anywhere/EMal/jump-anywhere.emal
Normal file
47
Task/Jump-anywhere/EMal/jump-anywhere.emal
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
^|EMal has no goto statement.
|
||||
|The closes statements are break, continue, return, exit
|
||||
|and exceptions management.
|
||||
|^
|
||||
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 specific code
|
||||
|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
|
||||
Loading…
Add table
Add a link
Reference in a new issue