corrected example
[rrq/rrqforth.git] / adoc / p_break.adoc
1 // control.asm: WORD p_break,'BREAK',fasm,IMMEDIATE
2
3 anchor:p_break[]
4
5 === Word: BREAK
6
7 "BREAK" is an immediate function word that lays out an unconditional
8 branch out of an enclosing xef:p_begin[BEGIN]-xref:p_end[END] block.
9 Similar to xref:p_ifbreak[IFBREAK] it lays out the branch cell
10 followed by a reserved cell for the branch offset, and inserts the
11 resolution address just above the required 0 on the data stack.
12
13 ====
14 .Usage example {counter:example}: unconditional break with a condition.
15 ----
16 : WTELL ( tfa -- ; Print word pname )
17   24 + DUP 8 + SWAP @ TELL SP EMIT
18 ;
19
20 : WORDS ( wordlist -- ; Print all words of word list )
21   BEGIN
22     @ DUP IF DUP WTELL ELSE BREAK THEN
23     1 IFAGAIN
24   END
25   DROP
26   NL EMIT
27 ;
28 ----
29 ====
30
31 See also <<p_branch,BRANCH>>, <<p_0branch,0BRANCH>>,
32 <<p_1branch,1BRANCH>>, <<p_if,IF>>, <<p_else,ELSE>>,
33 <<p_ifbreak,IFBREAK>> and <<p_ifagain,IFAGAIN>>.