mirror of
https://git.sr.ht/~crc_/retroforth
synced 2024-11-16 19:48:56 +01:00
book: add while and until to the loops section
FossilOrigin-Name: ed58c64354a8d116325f5e7c30f44b94d516e7f83866f926e5d68bba03055935
This commit is contained in:
parent
8407b50905
commit
6b3d7027a4
2 changed files with 18 additions and 0 deletions
|
@ -2469,6 +2469,15 @@ Be careful with recursion as the virtual machine will have a limited
|
|||
amount of space for the address stack and recursing too many times
|
||||
can cause a stack overflow.
|
||||
|
||||
## Conditional Loops
|
||||
|
||||
There are two conditional looping combinators: `while` and `until`.
|
||||
Both take a quote and execute it, checking a returned flag to decide
|
||||
when to stop running.
|
||||
|
||||
#0 [ dup n:put sp n:inc dup #10 eq? ] until
|
||||
#10 [ dup n:put sp n:dec dup n:-zero? ] while
|
||||
|
||||
## Counted Loops
|
||||
|
||||
There are two combinators for counted loops. These are `times` and
|
||||
|
|
|
@ -27,6 +27,15 @@ Be careful with recursion as the virtual machine will have a limited
|
|||
amount of space for the address stack and recursing too many times
|
||||
can cause a stack overflow.
|
||||
|
||||
## Conditional Loops
|
||||
|
||||
There are two conditional looping combinators: `while` and `until`.
|
||||
Both take a quote and execute it, checking a returned flag to decide
|
||||
when to stop running.
|
||||
|
||||
#0 [ dup n:put sp n:inc dup #10 eq? ] until
|
||||
#10 [ dup n:put sp n:dec dup n:-zero? ] while
|
||||
|
||||
## Counted Loops
|
||||
|
||||
There are two combinators for counted loops. These are `times` and
|
||||
|
|
Loading…
Reference in a new issue