Home > Archive > Fortran > April 2006 > rookie question: the do-loop in F77
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
rookie question: the do-loop in F77
|
|
| sunnylele 2006-04-25, 7:10 pm |
| HI, all,
when a do-loop written in F77 as:
do 50 i=1,ncmpt
y=i+1
do 50 j=1,nvox3
yscal(j+nvox3*(i-1))=eqmag(i)
50 continue
which "do 50" will it iterate when it reaches "50 continue"?
What is the difference between the above loop and the following:
do 50 i=1,ncmpt
y=i+1
do 51 j=1,nvox3
yscal(j+nvox3*(i-1))=eqmag(i)
51 continue
50 continue
The compiler is g77.
Thanks!
Jing
| |
| Michael Metcalf 2006-04-25, 7:10 pm |
|
"sunnylele" <sjsongjing@gmail.com> wrote in message
news:1145904353.355073.155060@y43g2000cwc.googlegroups.com...
> HI, all,
>
> when a do-loop written in F77 as:
> do 50 i=1,ncmpt
> y=i+1
> do 50 j=1,nvox3
> yscal(j+nvox3*(i-1))=eqmag(i)
> 50 continue
>
> which "do 50" will it iterate when it reaches "50 continue"?
> What is the difference between the above loop and the following:
> do 50 i=1,ncmpt
> y=i+1
> do 51 j=1,nvox3
> yscal(j+nvox3*(i-1))=eqmag(i)
> 51 continue
> 50 continue
>
Usually, none. But in the first form, a GO TO 50 may appear only within the
inner loop. The first form is also obsolescent and should not be used in new
code.
Regards,
Mike Metcalf
| |
| glen herrmannsfeldt 2006-04-25, 7:10 pm |
| sunnylele <sjsongjing@gmail.com> wrote:
> HI, all,
>
> when a do-loop written in F77 as:
> do 50 i=1,ncmpt
> y=i+1
> do 50 j=1,nvox3
> yscal(j+nvox3*(i-1))=eqmag(i)
> 50 continue
> which "do 50" will it iterate when it reaches "50 continue"?
Yes, that is a find set of nested DO loops.
> What is the difference between the above loop and the following:
> do 50 i=1,ncmpt
> y=i+1
> do 51 j=1,nvox3
> yscal(j+nvox3*(i-1))=eqmag(i)
> 51 continue
> 50 continue
Without an IF/GOTO to 50 or 51 the result should be exactly
the same. The latter has an advantage if you need to exit the
J loop early without exiting the I loop, and require or just like
using, the Fortran 66 loop constructs.
Note that in this case, you would also get the same result by
ending both loops at 50 on the yscal assignment, one or two
fewer statements.
do 50 i=1,ncmpt
y=i+1
do 50 j=1,nvox3
50 yscal(j+nvox3*(i-1))=eqmag(i)
Many will discourage you from these forms, using the DO/ENDDO
form instead. Personally, I would probably use this
form only for this simplest assignment with two or
more nesting levels.
-- glen
| |
|
|
"sunnylele" <sjsongjing@gmail.com> wrote in message
news:1145904353.355073.155060@y43g2000cwc.googlegroups.com...
> HI, all,
>
> when a do-loop written in F77 as:
> do 50 i=1,ncmpt
> y=i+1
> do 50 j=1,nvox3
> yscal(j+nvox3*(i-1))=eqmag(i)
> 50 continue
>
> which "do 50" will it iterate when it reaches "50 continue"?
> What is the difference between the above loop and the following:
> do 50 i=1,ncmpt
> y=i+1
> do 51 j=1,nvox3
> yscal(j+nvox3*(i-1))=eqmag(i)
> 51 continue
> 50 continue
>
> The compiler is g77.
>
> Thanks!
> Jing
>
There is no difference in meaning or action. The second form is easier for
humans to understand.
Jim
|
|
|
|
|