From 6b3d7027a4c9a2275765898faccf8ec438bbaf21 Mon Sep 17 00:00:00 2001 From: crc Date: Tue, 14 Jan 2020 19:14:55 +0000 Subject: [PATCH] book: add while and until to the loops section FossilOrigin-Name: ed58c64354a8d116325f5e7c30f44b94d516e7f83866f926e5d68bba03055935 --- doc/RETRO-Book.md | 9 +++++++++ doc/book/techniques/loops | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/doc/RETRO-Book.md b/doc/RETRO-Book.md index f3804a2..634c256 100644 --- a/doc/RETRO-Book.md +++ b/doc/RETRO-Book.md @@ -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 diff --git a/doc/book/techniques/loops b/doc/book/techniques/loops index 9cb9396..dca85f3 100644 --- a/doc/book/techniques/loops +++ b/doc/book/techniques/loops @@ -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