Jump to content

Flow-control structures: Difference between revisions

Line 1,399:
outer // m is 104
outer // m is 106
</syntaxhighlight>
 
====Using Break/Continue in Select Case====
Normally the Break statement break module (exit from module) or a Try { } block. Normally Continue is like exit in ordinary blocks or a new iteration for loop structures. For a Select case, a Break make the execution of other blocks from other cases to executed until "case else" or a continue statement. Both ends goes to end select. So break works in reverse of c's break.
 
<syntaxhighlight lang="m2000 interpreter">
Module checkSelect {
long m, i, k
for k=1 to 10
m=10
i=random(5, 10)
select case i
case <6
print "less than 6"
case 6
{
m++: break // break case block, and continue to next block
}
case 7
{
m++: break
}
case 8
{
m++: continue // exit after end select
}
case 9
print "is 9"
case else
print "more than 9"
end select
print m, i
next
}
checkSelect
</syntaxhighlight>
 
404

edits

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