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: iterative plotting: changing color/linestyle within a loop - comp ...Hi, I'm trying to perform iterative plotting while changing the color/linestyle within each iteration. Since the number of plots may vary I have cre... DOW Loop with multiple sum statements within by-group - comp.soft ...I have financial data sorted by Stock_Code and Date. Each Stock_Code by-group has between 0 and 19 announcement dates, approximately 6 months apart.... Loop within a Proc Mixed or Proc Autoreg statement - comp.soft-sys ...Hello, I have a spreadsheet of time series data. I have the returns of 25 different indices. And I want to do a AR 1 model of the market returns ... Write sequence text files within a loop - comp.soft-sys.matlab ...Write sequence text files within a loop - comp.soft-sys.matlab ... Writing non ASCII text files - comp.lang.tcl Write sequence text files within a loop - comp.soft ... How can I rename a structure name inside a loop? - comp.soft-sys ...Hi I have a database of structures with similar fields but different names (for simplicity, assume that there are 3 structures named, "John", "Mik... Use MPI inside a for loop - comp.parallel.mpiHello all, I need to make below code MPI'ed. Inside the "for" loop, there are 2 calls to function "solve" which is very heavy. So I wanted to make us... Plot points on the same plot inside a loop - comp.soft-sys.matlab ...Hello, I have set up a for loop. At the end of each iteration, I end up with a scalar value, which I append to a vector, d. Each iteration takes qu... generate/genvar, for loop and procdural (always/initial) block ...It describes how the generate works and how loops inside a generate statement are different from loops in a procedural block. Regards, Gabor closed loop in simulink - comp.soft-sys.matlabHi everyone, I am trying to model a closed loop system within the Simulink with Embedded Matlab functions (contains ODE's and fsolve functions). I... Double "for" loop problem.. - comp.soft-sys.matlab... and b that gave that min value of D using what you did after the loop - you'll have to get them using rowsForMin and colsForMins or else save them inside the for loop ... For loops in BASIC - comp.sys.apple2.programmerFor loops in BASIC - comp.sys.apple2.programmer Use MPI inside a for loop - comp.parallel.mpi For loops in BASIC - comp.sys.apple2.programmer So I can use one loop in ... Assigning Variables in a parfor loop - comp.soft-sys.matlab ...Dear all, I have a simulink model which references another model inside. I have a list of variables for the referenced model. I would like to run t... instead of For loop - comp.soft-sys.matlabiterative plotting: changing color/linestyle within a loop - comp ... instead of For loop - comp.soft-sys.matlab changing the variable name in a FOR loop - comp.soft-sys ... Advantages of for and while loops? - comp.soft-sys.matlab ...Saving value from for loop within while loop - comp.soft-sys ... I can't see how your WHILE loop ever ends, because x isn't incrementing towards 10. plot legend in for loop - comp.soft-sys.matlabI would like to append lines in the legend for every plot cycle in the following loop. The plotting takes place inside a function, which gets A=[] as ... Loop optimization - Wikipedia, the free encyclopediaunswitching : Unswitching moves a conditional inside a loop outside of it by duplicating the loop's body, and placing a version of it inside each of the if and else ... Loops within loops | Practical PHP Programming | TuxRadar LinuxLoops within loops. You can stack loops up as you see fit simply by having one loop inside the body of another, like this: 7/13/2012 10:34:17 PM
|