2N/A\ #ident "%Z%%M% %I% %E% SMI"
2N/A\ Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2N/A\ Use is subject to license terms.
2N/A\
2N/A\ CDDL HEADER START
2N/A\
2N/A\ The contents of this file are subject to the terms of the
2N/A\ Common Development and Distribution License, Version 1.0 only
2N/A\ (the "License"). You may not use this file except in compliance
2N/A\ with the License.
2N/A\
2N/A\ You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A\ or http://www.opensolaris.org/os/licensing.
2N/A\ See the License for the specific language governing permissions
2N/A\ and limitations under the License.
2N/A\
2N/A\ When distributing Covered Code, include this CDDL HEADER in each
2N/A\ file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A\ If applicable, add the following below this CDDL HEADER, with the
2N/A\ fields enclosed by brackets "[]" replaced with your own identifying
2N/A\ information: Portions Copyright [yyyy] [name of copyright owner]
2N/A\
2N/A\ CDDL HEADER END
2N/A\
2N/A
2N/A." Interactive begin .. while .. repeat: "
2N/A " no loop (1) " 1 begin 0 while 1- repeat .passed?
2N/A " loop to 0 (1)" 9 begin dup while 1- repeat 0= .passed?
2N/Acr
2N/A." Compiled begin .. while .. repeat: "
2N/A : btest1 1 begin 0 while 1- repeat .passed? ;
2N/A : btest2 9 begin dup while 1- repeat 0= .passed? ;
2N/A " no loop (2) " btest1
2N/A " loop to 0 (2)" btest2
2N/Acr
2N/A." Interactive begin..until: "
2N/A " no loop (3)" 1 begin dup until .passed?
2N/A " loop to 0 (3)" 9 begin 1- dup 0= until 0= .passed?
2N/Acr
2N/A." Compiled begin..until: "
2N/A : btest3 1 begin dup until .passed? ;
2N/A : btest4 9 begin 1- dup 0= until 0= .passed? ;
2N/A " no loop (4)" btest3
2N/A " loop to 0 (4)" btest4
2N/Acr
2N/A." Interactive do .. loop: "
2N/A " loop (1)" 0 h# 10 0 do drop i loop h# f = .passed?
2N/A " no loop (1)" 1 0 0 ?do 1- loop .passed?
2N/A " leave (1)" h# 10 0 do i 5 = if 1 leave drop 0 then loop .passed?
2N/Acr
2N/A." Compiled do .. loop: "
2N/A : loop1 do drop i loop h# f = .passed? ;
2N/A : loop2 ?do 1- loop .passed? ;
2N/A : loop3 do i 3 = if drop i leave 0 then loop ;
2N/A : loop7 do i 4 = if drop i unloop exit then loop ;
2N/A " loop (2)" 0 h# 10 0 loop1
2N/A " no loop (2)" 1 0 0 loop2
2N/A " leave (2)" 3 4 0 loop3 3 = .passed?
2N/A " unloop" 5 6 0 loop7 4 = .passed?
2N/Acr
2N/A." Interactive do .. +loop: "
2N/A " loop by 2" 0 h# 10 0 do drop i 2 +loop h# e = .passed?
2N/A " loop down by 2" 0 -2 h# 10 do drop i -2 +loop h# -2 = .passed?
2N/Acr
2N/A." Compiled do .. +loop: "
2N/A : loop4 0 h# 10 0 do drop i 2 +loop h# e = .passed? ;
2N/A : loop5 0 -2 h# 10 do drop i -2 +loop -2 = .passed? ;
2N/A " loop (4)" loop4
2N/A " loop (5)" loop5
2N/Acr
2N/A." Nested loops: "
2N/A : loop6 0 h# 4 0 do 8 0 do 1 j 3 lshift i + lshift xor loop loop ;
2N/A " i,j sum" loop6 lwsplit over = swap h# ffff = and .passed?
2N/Acr
2N/A." Negative Limit Loops: "
2N/A " loop.7" h# 10 -37 8 bounds do drop i loop -30 = .passed?
2N/A " loop.8" h# 10 -37 -30 do drop i -1 +loop -37 = .passed?
2N/Acr
2N/A." Compiled begin...again: "
2N/A : loop9 begin true exit again false ; loop9 " loop9" rot .passed?
2N/A 0 value in-count
2N/A 0 value out-count
2N/A : loop10
2N/A begin
2N/A out-count 1+ to out-count
2N/A begin
2N/A in-count 10 >= if
2N/A exit
2N/A then in-count 1+ to in-count
2N/A again
2N/A -1 to in-count
2N/A exit
2N/A again
2N/A -2 to in-count
2N/A ;
2N/A " loop.10" loop10 in-count 10 = out-count 1 = and .passed?
2N/Acr