book: add while and until to the loops section

FossilOrigin-Name: ed58c64354a8d116325f5e7c30f44b94d516e7f83866f926e5d68bba03055935
This commit is contained in:
crc 2020-01-14 19:14:55 +00:00
parent 8407b50905
commit 6b3d7027a4
2 changed files with 18 additions and 0 deletions

View file

@ -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

View file

@ -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