1*0Sstevel@tonic-gate\ #ident "%Z%%M% %I% %E% SMI" 2*0Sstevel@tonic-gate\ Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3*0Sstevel@tonic-gate\ Use is subject to license terms. 4*0Sstevel@tonic-gate\ 5*0Sstevel@tonic-gate\ CDDL HEADER START 6*0Sstevel@tonic-gate\ 7*0Sstevel@tonic-gate\ The contents of this file are subject to the terms of the 8*0Sstevel@tonic-gate\ Common Development and Distribution License, Version 1.0 only 9*0Sstevel@tonic-gate\ (the "License"). You may not use this file except in compliance 10*0Sstevel@tonic-gate\ with the License. 11*0Sstevel@tonic-gate\ 12*0Sstevel@tonic-gate\ You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 13*0Sstevel@tonic-gate\ or http://www.opensolaris.org/os/licensing. 14*0Sstevel@tonic-gate\ See the License for the specific language governing permissions 15*0Sstevel@tonic-gate\ and limitations under the License. 16*0Sstevel@tonic-gate\ 17*0Sstevel@tonic-gate\ When distributing Covered Code, include this CDDL HEADER in each 18*0Sstevel@tonic-gate\ file and include the License file at usr/src/OPENSOLARIS.LICENSE. 19*0Sstevel@tonic-gate\ If applicable, add the following below this CDDL HEADER, with the 20*0Sstevel@tonic-gate\ fields enclosed by brackets "[]" replaced with your own identifying 21*0Sstevel@tonic-gate\ information: Portions Copyright [yyyy] [name of copyright owner] 22*0Sstevel@tonic-gate\ 23*0Sstevel@tonic-gate\ CDDL HEADER END 24*0Sstevel@tonic-gate\ 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gate." Interactive begin .. while .. repeat: " 27*0Sstevel@tonic-gate " no loop (1) " 1 begin 0 while 1- repeat .passed? 28*0Sstevel@tonic-gate " loop to 0 (1)" 9 begin dup while 1- repeat 0= .passed? 29*0Sstevel@tonic-gatecr 30*0Sstevel@tonic-gate." Compiled begin .. while .. repeat: " 31*0Sstevel@tonic-gate : btest1 1 begin 0 while 1- repeat .passed? ; 32*0Sstevel@tonic-gate : btest2 9 begin dup while 1- repeat 0= .passed? ; 33*0Sstevel@tonic-gate " no loop (2) " btest1 34*0Sstevel@tonic-gate " loop to 0 (2)" btest2 35*0Sstevel@tonic-gatecr 36*0Sstevel@tonic-gate." Interactive begin..until: " 37*0Sstevel@tonic-gate " no loop (3)" 1 begin dup until .passed? 38*0Sstevel@tonic-gate " loop to 0 (3)" 9 begin 1- dup 0= until 0= .passed? 39*0Sstevel@tonic-gatecr 40*0Sstevel@tonic-gate." Compiled begin..until: " 41*0Sstevel@tonic-gate : btest3 1 begin dup until .passed? ; 42*0Sstevel@tonic-gate : btest4 9 begin 1- dup 0= until 0= .passed? ; 43*0Sstevel@tonic-gate " no loop (4)" btest3 44*0Sstevel@tonic-gate " loop to 0 (4)" btest4 45*0Sstevel@tonic-gatecr 46*0Sstevel@tonic-gate." Interactive do .. loop: " 47*0Sstevel@tonic-gate " loop (1)" 0 h# 10 0 do drop i loop h# f = .passed? 48*0Sstevel@tonic-gate " no loop (1)" 1 0 0 ?do 1- loop .passed? 49*0Sstevel@tonic-gate " leave (1)" h# 10 0 do i 5 = if 1 leave drop 0 then loop .passed? 50*0Sstevel@tonic-gatecr 51*0Sstevel@tonic-gate." Compiled do .. loop: " 52*0Sstevel@tonic-gate : loop1 do drop i loop h# f = .passed? ; 53*0Sstevel@tonic-gate : loop2 ?do 1- loop .passed? ; 54*0Sstevel@tonic-gate : loop3 do i 3 = if drop i leave 0 then loop ; 55*0Sstevel@tonic-gate : loop7 do i 4 = if drop i unloop exit then loop ; 56*0Sstevel@tonic-gate " loop (2)" 0 h# 10 0 loop1 57*0Sstevel@tonic-gate " no loop (2)" 1 0 0 loop2 58*0Sstevel@tonic-gate " leave (2)" 3 4 0 loop3 3 = .passed? 59*0Sstevel@tonic-gate " unloop" 5 6 0 loop7 4 = .passed? 60*0Sstevel@tonic-gatecr 61*0Sstevel@tonic-gate." Interactive do .. +loop: " 62*0Sstevel@tonic-gate " loop by 2" 0 h# 10 0 do drop i 2 +loop h# e = .passed? 63*0Sstevel@tonic-gate " loop down by 2" 0 -2 h# 10 do drop i -2 +loop h# -2 = .passed? 64*0Sstevel@tonic-gatecr 65*0Sstevel@tonic-gate." Compiled do .. +loop: " 66*0Sstevel@tonic-gate : loop4 0 h# 10 0 do drop i 2 +loop h# e = .passed? ; 67*0Sstevel@tonic-gate : loop5 0 -2 h# 10 do drop i -2 +loop -2 = .passed? ; 68*0Sstevel@tonic-gate " loop (4)" loop4 69*0Sstevel@tonic-gate " loop (5)" loop5 70*0Sstevel@tonic-gatecr 71*0Sstevel@tonic-gate." Nested loops: " 72*0Sstevel@tonic-gate : loop6 0 h# 4 0 do 8 0 do 1 j 3 lshift i + lshift xor loop loop ; 73*0Sstevel@tonic-gate " i,j sum" loop6 lwsplit over = swap h# ffff = and .passed? 74*0Sstevel@tonic-gatecr 75*0Sstevel@tonic-gate." Negative Limit Loops: " 76*0Sstevel@tonic-gate " loop.7" h# 10 -37 8 bounds do drop i loop -30 = .passed? 77*0Sstevel@tonic-gate " loop.8" h# 10 -37 -30 do drop i -1 +loop -37 = .passed? 78*0Sstevel@tonic-gatecr 79*0Sstevel@tonic-gate." Compiled begin...again: " 80*0Sstevel@tonic-gate : loop9 begin true exit again false ; loop9 " loop9" rot .passed? 81*0Sstevel@tonic-gate 0 value in-count 82*0Sstevel@tonic-gate 0 value out-count 83*0Sstevel@tonic-gate : loop10 84*0Sstevel@tonic-gate begin 85*0Sstevel@tonic-gate out-count 1+ to out-count 86*0Sstevel@tonic-gate begin 87*0Sstevel@tonic-gate in-count 10 >= if 88*0Sstevel@tonic-gate exit 89*0Sstevel@tonic-gate then in-count 1+ to in-count 90*0Sstevel@tonic-gate again 91*0Sstevel@tonic-gate -1 to in-count 92*0Sstevel@tonic-gate exit 93*0Sstevel@tonic-gate again 94*0Sstevel@tonic-gate -2 to in-count 95*0Sstevel@tonic-gate ; 96*0Sstevel@tonic-gate " loop.10" loop10 in-count 10 = out-count 1 = and .passed? 97*0Sstevel@tonic-gatecr 98