Skip to content

Instantly share code, notes, and snippets.

@blippy
Created January 20, 2020 14:33
Show Gist options
  • Save blippy/42ddba2c141580c0b64f57c534f3c197 to your computer and use it in GitHub Desktop.
Save blippy/42ddba2c141580c0b64f57c534f3c197 to your computer and use it in GitHub Desktop.
Execute a block of code n times
: 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
@blippy
Copy link
Author

blippy commented Jan 20, 2020

Execute a <times ... times>. You can even embed it. eg1 outputs the results

.....

eg2 outputs:

XXXX
XXXX
XXXX
XXXX
XXXX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment