Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!SUN.COM!wmb From: wmb@SUN.COM Newsgroups: comp.lang.forth Subject: Re: New Directions: 'I' is broken in Forth Message-ID: <9001241639.AA08039@jade.berkeley.edu> Date: 23 Jan 90 21:12:11 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: Forth Interest Group International List Organization: The Internet Lines: 36 > Besides the names, what is the difference? [ between DO .. LOOP and > FOR .. NEXT ] Explanation by example: 0 FOR ." x" NEXT --> x 1 FOR ." x" NEXT --> xx 2 FOR ." x" NEXT --> xxx -1 FOR ." x" NEXT --> xxxxxxxxxxxxxxxxxxxxxxxxxxx (and so on!) This is efficient to implement in hardware; for instance, it maps pretty much directly onto the 680x0 DBRA instruction. > There is nothing wrong with the do-loop in forth other than the ugly > way the index variable is handled. Some things wrong with the standard Forth DO .. LOOP: Can't EXIT from inside a DO ... LOOP Can't intermix use of the return stack and loop indices Termination conditions for +LOOP with positive and negative arguments is not symmetrical. It always executes at least once. This is nearly always the wrong thing. ?DO helps, but ?DO doesn't work well with negative arguments to +LOOP I use DO .. LOOP all the time, but there are definitely some problems with it. Mitch