From: Joey Wong
Subject: nesting for loops
Date: 
Message-ID: <8dkhts$iml$1@ftp.curtin.edu.au>
I'm just starting LISP and was wondering if nested for loops are ok

From: Joe Marshall
Subject: Re: nesting for loops
Date: 
Message-ID: <u1z3srjst.fsf@alum.mit.edu>
"Joey Wong" <······@ses.curtin.edu.au> writes:

> I'm just starting LISP and was wondering if nested for loops are ok
You can nest loops.

Wait 'til you start nesting functions, though!
From: David Bakhash
Subject: Re: nesting for loops
Date: 
Message-ID: <m3itx4hp10.fsf@alum.mit.edu>
Joe Marshall <·········@alum.mit.edu> writes:

> "Joey Wong" <······@ses.curtin.edu.au> writes:
> 
> > I'm just starting LISP and was wondering if nested for loops are ok
> You can nest loops.
> 
> Wait 'til you start nesting functions, though!

yeah.  I was wondering if there's a language that _doesn't_ let you
nest loops.  Of course, he could have meant "recursion", and just
expressed it a bit oddly.

dave
From: Kragen Sitaker
Subject: Re: nesting for loops
Date: 
Message-ID: <osEN4.9629$%i.3580454@news-east.usenetserver.com>
In article <··············@alum.mit.edu>,
David Bakhash  <·····@alum.mit.edu> wrote:
>Joe Marshall <·········@alum.mit.edu> writes:
>> "Joey Wong" <······@ses.curtin.edu.au> writes:
>> 
>> > I'm just starting LISP and was wondering if nested for loops are ok
>> You can nest loops.
>> 
>> Wait 'til you start nesting functions, though!
>
>yeah.  I was wondering if there's a language that _doesn't_ let you
>nest loops.  Of course, he could have meant "recursion", and just
>expressed it a bit oddly.

FORTH is a little weird with regard to its loops; you can nest them as
deep as you like, but you can typically only access the loop counters
of the top two or three loops on the stack.  (Well, actually, you can
write nonportable code to grovel through the rstack and find the other
loop counters, but that's beside the point.)

x86 assembler has a LOOP instruction that implicitly decrements CX
(ECX?  I don't know 386 asm).  You can only nest loops built with these
guys if you go to extra trouble to save and restore CX.

I can't think of any other languages that have restrictions on nesting
loops.
-- 
<······@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08.  Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
The power didn't go out on 2000-01-01 either.  :)
From: Courageous
Subject: Re: nesting for loops
Date: 
Message-ID: <39067338.DA482841@san.rr.com>
> I'm just starting LISP and was wondering if nested for loops are ok

What is it that lead you to believe you needed to ask this
question? Do you find something strange or suspect about
nested loops? And which lisp forms are you referring to
specifically?


C/
From: Christopher Browne
Subject: Re: nesting for loops
Date: 
Message-ID: <zCLN4.22089$VR.521958@news5.giganews.com>
Centuries ago, Nostradamus foresaw a time when Joey Wong would say:
>I'm just starting LISP and was wondering if nested for loops are ok

Several answers:

a) FOR is neither a macro nor a function, so there's no such thing as
a "for loop."

b) Using a nested LOOP _may_ be indicative that you didn't use LOOP
properly, as you can put almost infinite complexity into a single
LOOP.

c) A nested loop _may_ be indicative of questionable factoring.
Functions that nest loops are pretty much guaranteed to be complex,
and thus may indicate that you should have created a "helper
function."

[To the picky, I said "may indicate" as opposed to "always
indicates".]

d) Aside from those other issues, nothing technical prevents you from
having control structures nested 45 levels deep.
-- 
Have you heard of the new Macsyma processor?  It has three instructions --
LOAD, STORE, and SKIP IF INTEGRABLE.
········@ntlug.org- <http://www.ntlug.org/~cbbrowne/lsf.html>
From: Barry Margolin
Subject: Re: nesting for loops
Date: 
Message-ID: <DsYN4.5$xb5.553@burlma1-snr2>
In article <·····················@news5.giganews.com>,
Christopher Browne <········@hex.net> wrote:
>b) Using a nested LOOP _may_ be indicative that you didn't use LOOP
>properly, as you can put almost infinite complexity into a single
>LOOP.

I suppose this is possible, but I don't think it's likely.  Nested loops
are extremely common whenever you're traversing multi-dimensional
structures, e.g. a 2-d array with

  (loop for i upto length
    do
    (loop for j upto width
      do
      (do-something-with (aref a i j))))

or a list of lists with:

  (loop for inner in outer
    do
    (loop for item in inner
      do
      (do-something-with item)))

LOOP has quite a bit of complexity, but it doesn't actually have any way to
do either of these easily in a single loop (well, in the first case you
could do it with ROW-MAJOR-AREF, but that's not really a LOOP feature,
that's a special array feature).

-- 
Barry Margolin, ······@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.