1234567891011121314151617181920212223242526272829303132 |
- \ Looping is fine, but what, if one needs to break a loop?
- : mydef
- 10 5 u+do
- i 2 mod 0 =
- if
- ." at index: " i . cr
- ." hit an even number -- oh noes!" cr
- \ Need to call `unloop` to not mess up everything. Loops
- \ have implicit variables on the stack, to represent
- \ their state. These variables need to be cleaned up
- \ before exiting.
- unloop
- \ exit leaves the current definition. So it is like
- \ `return` in other languages.
- exit
- then
- loop ;
- : mydef
- 10 5 u+do
- i 2 mod 0 =
- if
- ." at index: " i . cr
- ." hit an even number -- oh noes!" cr
- \ `leave` seems to do both, `unloop` and `exit`. It is a
- \ cleaner way of doing things, because there is no way
- \ to forget to unloop.
- leave
- then
- loop ;
|