Created
January 20, 2020 14:33
-
-
Save blippy/42ddba2c141580c0b64f57c534f3c197 to your computer and use it in GitHub Desktop.
Execute a block of code n times
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
: nneg 0 >= ; | |
: <times postpone >r postpone begin postpone r> postpone 1- postpone dup | |
postpone >r postpone nneg postpone while ; immediate | |
: times> postpone repeat postpone rdrop ; immediate | |
\ Simple usage: | |
: eg1 5 <times '. emit times> cr ; | |
eg1 | |
\ You can even embed blocks: | |
: eg2 5 <times 4 <times 'X emit times> cr times> ; | |
eg2 | |
bye |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Execute a
<times ... times>
. You can even embed it.eg1
outputs the resultseg2
outputs: