Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: re: Fortran 77s GOTO


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: re: Fortran 77s GOTO
Date   Tue, 16 Oct 2007 14:21:44 -0400

Joe said

A question about translating the following snippet of FORTRAN 77 into  
Mata:

           DO 120 J=1,NCV
. . .
           IF (SM) 100,120,100
   100     SM=SM*B
. . .
   120     CONTINUE

I currently have the following (perhaps-too-literal) translation:

     for (j=1; j<=ncv; j++) {
. . .
         if (!sm) goto L120
         sm = sm * b
. . .
L120: }

But in an aside exploration of Mata's behavior with an analogous probe
function, it seems that when a -goto- sends control to the  
continuation line
as above, it behaves like a -break- and not a -continue-.  Is it that  
I'm
misremembering things FORTRAN?  (The algorithm is still a little
difficult to follow at the moment, so the intention isn't obvious  
from the
context.)

Can someone with a more trustworthy memory clue me in, and recommend  
one of
the following as the replacement--or maybe suggest something better  
still?

A:
     for (j=1; j<=ncv; j++) {
. . .
         if (!sm) continue
         sm = sm * b
. . .
     }

B:
     for (j=1; j<=ncv; j++) {
. . .
         if (!sm) break
         sm = sm * b
. . .
     }




Why not just do

for(j=1; j<=ncv; j++) {
    if(sm) {
	sm = sm*b
        ...
       ...
	}
}





*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index