Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
56
Task/Loops-Do-while/M2000-Interpreter/loops-do-while.m2000
Normal file
56
Task/Loops-Do-while/M2000-Interpreter/loops-do-while.m2000
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue