Loops/Do-while: Difference between revisions
Content deleted Content added
Line 2,064: | Line 2,064: | ||
} |
} |
||
Old_Style |
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 |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
Line 2,071: | Line 2,091: | ||
1 2 3 4 5 6 |
1 2 3 4 5 6 |
||
1 2 3 4 5 6 |
1 2 3 4 5 6 |
||
1 |
|||
2 |
|||
3 |
|||
4 |
|||
5 |
|||
6 |
|||
1 |
1 |
||
2 |
2 |