RosettaCodeData/Task/Loops-Do-while/M2000-Interpreter/loops-do-while.m2000

57 lines
1.1 KiB
Plaintext

Module checkit {
x=0
\\ Do or Repeat
Do
x++
print x,
when x mod 6>0
print
// or we can use Until x mod 6 = 0
// and we can use block if we like it
x=0
Do {
x++
print x,
} when x mod 6>0
print
x=0
{
\\ when enter to block the loop flag change to false
x++
if x mod 6<>0 Then loop ' set loop flag of current block to true
\\ when block end check Loop flag and if true execute block again
print x,
}
print
}
Checkit
module Old_Style {
10 REM Loops/Do-while
20 LET I=0
30 LET I=I+1
40 PRINT I
50 IF INT(I/6)*6 <> I THEN 30
60 END
}
Old_Style
// modern style, using high order functions
module generic_iterator {
do_while = lambda (f, p)->{
{
if p(f()) then loop
}
}
funcA=lambda (start_from, do_what) -> {
=lambda i=start_from, do_what ->{
call do_what(i)
=i
i++
}
}
funcPrint=lambda ->{
print number
}
call do_while(funcA(1, funcPrint), lambda->number mod 6 <>0)
}
generic_iterator