Jump to content

Flow-control structures: Difference between revisions

Line 1,323:
Every is a block structure for execution code synchronized by timer. If code exit execution time of block's constant time, executed later at same phase. There are three more statements for tasks, AFTER, THREAD and MAIN.TASK for executing code based on time in sequential of concurrent fashion, not shown here.
 
We can use Error "name of error" to produce error and we can catch it through a Try block.
 
 
====Use of Labels====
<syntaxhighlight lang="m2000 interpreter">
Module Inner {
Line 1,362 ⟶ 1,366:
}
Inner
</syntaxhighlight>
 
====Use of Call Back function====
M2000 has no yield statement/function. We can use a call back function to get results, before a module exit. The call back function act as code in the calling module (has same scope), but has a difference: we can't use goto/gosub out of it
 
<syntaxhighlight lang="m2000 interpreter">
module outer {
static m as long=100 // if m not exist created
module count (&a(), b) {
long c=1
do
if b(c) then exit
call a(c)
c++
always
}
long z, i=100
// function k used as call back function, through lazy$()
function k {
read new i
print i // print 1 and 2
z+=i
m++
}
count lazy$(&k()), (lambda (i)->i>=3)
print z=3, i=100, m
}
clear // clear variables (and static variables) from this point
outer // m is 102
outer // m is 104
outer // m is 106
</syntaxhighlight>
 
404

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.