Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!willett!ForthNet From: ForthNet@willett.UUCP (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: All Sorts of Sorts Message-ID: <617.UUL1.3#5129@willett.UUCP> Date: 6 Mar 90 01:04:24 GMT Organization: Latest link in the ForthNet chain. (Pgh, PA) Lines: 38 Category 3, Topic 37 Message 31 Sun Mar 04, 1990 F.SERGEANT [Frank] at 21:52 CST To Steve & Ian, SP> : LOOP_DEMONSTRATION ( n2 n1 -- ) SP> \ That is, both the inner and outer loop limits are on the stack SP> \ before this word executes. You could put them there by fetching SP> \ from a couple of variables, or whatever other means you like. SP> 1 DO ( Takes n1 from param stack, puts in on Rstack ) SP> 1 DO ( Takes n2 from param stack, puts it on Rstack ) SP> ( whatever you want to execute ) SP> LOOP SP> LOOP ; Nope, the above will not work (unless n1 is 1). The 2nd & subsequent passes thru the outer loop will have no limit available on the stack for the inner loop. You need a DUP after the 1st DO and a DROP after the last LOOP. Also, I keep seeing these "1"s as beginning indexes for your loops in these messages. Presumably you want to say something like 10 STARS and have your word STARS print ten of 'em. If you define STARS with a built-in index of 1, you'd have to say 11 STARS to get 10 of 'em. : STARS ( #-of-stars-desired - ) 0 DO STAR LOOP ; or : STARS ( 1-more-than-#-of-stars-desired - ) 1 DO STAR LOOP ; On the other hand, you might want to use a built-in index of 1 when you plan to use the index inside of the loop, eg for addressing a one based array. I would think the more common situation would be to use a zero based array, in which case you would still use a starting index of 1. Any questions? (By the way, I don't use DO LOOP anymore, just FOR NEXT.) -- Frank ----- This message came from GEnie via willett through a semi-automated process. Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'