Loop within Loop?

  • Follow


Is it allowed to have one do loop completely within another
do loop in Fortran?

0
Reply anonymous921 (90) 3/28/2011 1:34:58 AM

On 3/27/2011 8:34 PM, Anne Onime wrote:
> Is it allowed to have one do loop completely within another
> do loop in Fortran?

Of course...know of no programming language that prohibits such a 
construct.  Why the question re: Fortran?

--



0
Reply dpb 3/28/2011 2:16:22 AM


dpb <none@non.net> wrote:

> On 3/27/2011 8:34 PM, Anne Onime wrote:
> > Is it allowed to have one do loop completely within another
> > do loop in Fortran?
> 
> Of course...know of no programming language that prohibits such a 
> construct.  Why the question re: Fortran?

It is not only allowed, it is very, very common. There probably exist
non-trivial programs that don't have such a thing, but they are likely
rare. As dpb notes, that applies to most languages.

-- 
Richard Maine                    | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle           |  -- Mark Twain
0
Reply nospam 3/28/2011 3:32:30 AM

Anne Onime <anonymous@rip.ax.lt> wrote:

> Is it allowed to have one do loop completely within another
> do loop in Fortran?

It definitely does not allow one do loop partially
within another.  Completely within goes back to Fortran I,
allong with extended-range-of-the-DO.  (I believe the latter
has now been removed, though.)

-- glen
0
Reply glen 3/28/2011 5:10:00 AM

On 3/28/2011 2:34 PM, Anne Onime wrote:
> Is it allowed to have one do loop completely within another
> do loop in Fortran?
>

I think the deepest nesting I ever did was about 6.
0
Reply Gib 3/28/2011 6:33:59 AM

On Mar 28, 8:33=A0am, Gib Bogle <g.bo...@auckland.ac.nz> wrote:
> On 3/28/2011 2:34 PM, Anne Onime wrote:
>
> > Is it allowed to have one do loop completely within another
> > do loop in Fortran?
>
> I think the deepest nesting I ever did was about 6.

My sudoku programs go to a depth of 8 (=3D 9 - 1).

Regards,

Mike Metcalf
0
Reply m_b_metcalf 3/28/2011 6:54:05 AM

m_b_metcalf <michaelmetcalf@compuserve.com> wrote:

> On Mar 28, 8:33 am, Gib Bogle <g.bo...@auckland.ac.nz> wrote:
> > On 3/28/2011 2:34 PM, Anne Onime wrote:
> >
> > > Is it allowed to have one do loop completely within another
> > > do loop in Fortran?
> >
> > I think the deepest nesting I ever did was about 6.
> 
> My sudoku programs go to a depth of 8 (= 9 - 1).

I think I once ran into a compiler with a limit of 7 or so, which I once
hit. But it was a long time ago, and the memory is vague.

-- 
Richard Maine                    | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle           |  -- Mark Twain
0
Reply nospam 3/28/2011 7:38:35 AM

On 3/27/2011 8:34 PM, Anne Onime wrote:
> Is it allowed to have one do loop completely within another
> do loop in Fortran?
>
Try solving Dudeney puzzle of 1924 by writing a Fortran program:

Find single-decimal-digit values of the letters in the following addition:

        S E N D
    +   M O R E
      ---------
    = M O N E Y

If you take a simple enumerative approach, you will use an 8-deep nested 
loop.

-- mecej4
0
Reply mecej4 3/28/2011 12:25:24 PM

Richard Maine <nospam@see.signature> wrote:

(snip on DO nesting depth)

> I think I once ran into a compiler with a limit of 7 or so, which I once
> hit. But it was a long time ago, and the memory is vague.

I believe I have known optimizing compilers that would stop
optimizing deeply nested loops, but I don't remember one that
disallowed them.

-- glen
0
Reply glen 3/28/2011 12:36:59 PM

On 3/28/11 1:33 AM, Gib Bogle wrote:
> On 3/28/2011 2:34 PM, Anne Onime wrote:
>> Is it allowed to have one do loop completely within another
>> do loop in Fortran?
>>
>
> I think the deepest nesting I ever did was about 6.

I once saw a nesting that went 15 deep!  It was in a bug report where 
the user was complaining about the spelling in the error message.  We 
changed the spelling and he was happy, or at least stopped complaining.

Dick Hendrickson
0
Reply Dick 3/28/2011 2:52:27 PM

Op 28-03-11 03:34, Anne Onime schreef:
> Is it allowed to have one do loop completely within another
> do loop in Fortran?
>
Hi Anne,


Yes, that is how I solve Laplace equation using Gauss-Seidel iterations.

With 2 level do loops for a 2D equation.

Check out: http://fortran.kootsttra.org.uk/sources/laplace and 
http://fortran.kootstra.org.uk/docs/laplace

Compilation and linking works for Intel Fortran on Linux. Other 
compilers I did not test.


Kind regards,


Jan Gerrit
0
Reply Jan 3/28/2011 4:54:08 PM

On Mar 27, 9:34=A0pm, Anne Onime <anonym...@rip.ax.lt> wrote:
> Is it allowed to have one do loop completely within another
> do loop in Fortran?

One common application of nested DO loops is the representation of
matrices. I have an example here:
<http://groups.google.com/group/comp.lang.fortran/msg/
26e5af6a7af410c7>

Google for "fortran matrices DO loops". Here are some more examples:
<http://jblevins.org/log/array-write>
<http://orion.math.iastate.edu/burkardt/papers/
fortran_arrays.html#Loop_Unrolling>

agt
--
Freedom - no pane, all gaiGN!

Code Art Now
http://codeartnow.com
Email: a...@codeartnow.com
0
Reply viper 3/28/2011 5:39:44 PM

"Richard Maine" <nospam@see.signature> wrote in message 
news:1jytdqj.1v519whc00n8qN%nospam@see.signature...
> m_b_metcalf <michaelmetcalf@compuserve.com> wrote:
>
>> On Mar 28, 8:33 am, Gib Bogle <g.bo...@auckland.ac.nz> wrote:
>> > On 3/28/2011 2:34 PM, Anne Onime wrote:
>> >
>> > > Is it allowed to have one do loop completely within another
>> > > do loop in Fortran?
>> >
>> > I think the deepest nesting I ever did was about 6.
>>
>> My sudoku programs go to a depth of 8 (= 9 - 1).
>
> I think I once ran into a compiler with a limit of 7 or so, which I once
> hit. But it was a long time ago, and the memory is vague.
>

In a previous employment, some of my erstwhile colleagues wrestled for some 
months with (what appeared to be) an intermittent bug in the Fortran 
compiler, that manifested as the compiler error "Do-loops are nested more 
than 64 deep". Turned out to be a hardware problem.


-- 
Qolin

Email: my qname at domain dot com
Domain: qomputing 


0
Reply boss1 (30) 3/28/2011 10:35:10 PM

mecej4 <mecej4_nospam@operamail.com> wrote:
> Try solving Dudeney puzzle of 1924 by writing a Fortran program:
 
> Find single-decimal-digit values of the letters in the following addition:
 
>        S E N D
>    +   M O R E
>      ---------
>    = M O N E Y

Runs in 0.08s on this computer.
It could be faster by changing the loop order, such that
some of the IF statements could be moved up.  

      integer s,e,n,d,m,o,r,y
      do 1 s=0,9
      do 1 e=0,9
      if(s.eq.e) goto 1
      do 2 n=0,9
      if(s.eq.n.or.e.eq.n) goto 2
      do 3 d=0,9
      if(d.eq.s.or.d.eq.e.or.d.eq.n) goto 3
      do 4 m=0,9
      if(m.eq.s.or.m.eq.e.or.m.eq.n.or.m.eq.d) goto 4
      do 5 o=0,9
      if(o.eq.s.or.o.eq.e.or.o.eq.n.or.o.eq.d.or.o.eq.m) goto 5
      do 6 r=0,9
      if(r.eq.s.or.r.eq.e.or.r.eq.n) goto 6
      if(r.eq.d.or.r.eq.m.or.r.eq.o) goto 6
      do 7 y=0,9
      if(y.eq.s.or.y.eq.e.or.y.eq.n) goto 7
      if(y.eq.d.or.y.eq.m.or.y.eq.o) goto 7
      if(y.eq.r) goto 7
      if(mod(d+e,10).ne.y) goto 7
      if(mod(n+r+(d+e)/10,10).ne.e) goto 7
      if(mod(e+o+(n+r+(d+e)/10)/10,10).ne.n) goto 7
      if(mod(s+m+(e+o+(n+r+(d+e)/10)/10)/10,10).ne.o) goto 7
      if((s+m+(e+o+(n+r+(d+e)/10)/10)/10)/10.ne.m) goto 7
      if(m.eq.0) goto 7
      print *,  s,e,n,d
      print *,  m,o,r,e
      print *,m,o,n,e,y
7     continue
6     continue
5     continue
4     continue
3     continue
2     continue
1     continue
      stop
      end


-- glen
0
Reply gah (12241) 3/29/2011 7:40:21 AM

13 Replies
173 Views

(page loaded in 0.143 seconds)

Similiar Articles:


















7/13/2012 10:34:17 PM


Reply: