RosettaCodeData/Task/Jump-anywhere/M2000-Interpreter/jump-anywhere-3.m2000

81 lines
1.8 KiB
Plaintext

Module LikeGo {
\\ simulate Go for
\\ need to make var Empty, swapping uninitialized array item
Module EmptyVar (&x) {
Dim A(1)
Swap A(0), x
}
Function GoFor(&i, first, comp$, step$) {
\\ checking for empty we now if i get first value
if type$(i)="Empty" then {
i=first
} else {
i+=Eval(step$)
}
if Eval("i"+comp$) Else Exit
=true
}
def i, j
EmptyVar &i
outer:
{
if GoFor(&i, 0, "<4", "+1") else exit
EmptyVar &j
{
if GoFor(&j, 0, "<4", "+1") else exit
if i+j== 4 then goto outer
if i+j == 5 then goto break_outer
print i+j
loop
}
loop
}
break_outer:
k = 3
if k == 3 Then Goto later
Print k \\ never executed
later:
k++
Print k
}
LikeGo
\\ or we can use For {} block and put label outer to right place
Module LikeGo {
For i=0 to 3 {
For j=0 to 3 {
if i+j== 4 then goto outer
if i+j == 5 then goto break_outer
print i+j
}
outer:
}
break_outer:
k = 3
if k == 3 Then Goto later
Print k \\ never executed
later:
k++
Print k
}
LikeGo
Module LikeGo_No_Labels {
For i=0 to 3 {
For j=0 to 3 {
if i+j== 4 then exit ' exit breaks only one block
if i+j == 5 then break ' break breaks all blocks, but not the Module's block.
print i+j
}
}
k = 3
if k == 3 Else {
Print k \\ never executed
}
k++
Print k
}
LikeGo_No_Labels