Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

What's wrong with this FORTRAN loop?

DO 10 J = 1 TO 9999

N = 71631*J

K = N/100

Comment: the K will simply be a truncation.

IF MOD(K,1000) .EQ. 1 THEN

WRITE (6,*) 'SUCCESS AT ', J, ' ', N

STOP

ENDIF

10 CONTINUE

WRITE(6,*) 'NO LUCK FOR J < 10000'

END

Attachment image

2 Answers

Relevance
  • Adrian
    Lv 7
    2 years ago
    Favorite Answer

    Not quite the Fortran I'm used to (I've not really used Fortran-77)...

    A loop normally looks like:

    For J = 1 to 9999

    ...

    code

    ...

    Next J

    However, F77 does seem to allow your construct of a DO loop except it is DO 10 J = 1,9999

    You do not show your declarations for J,N,K. If they are Integer, values are too big and will overflow. If double Integer (I*4), then it should be ok.

    ENDIF should be two words END and IF

  • 2 years ago

    What is wrong that you spend no time looking up the correct syntax for each line that had an error.

    3 quick googles of queries like "fortran if" gave sites like https://pages.mtu.edu/~shene/COURSES/cs201/NOTES/c... with the correct syntax.

    The Do line error is becuse it looks like a BASIC DO with the TO rather than a comma.

    The comment line need an ! inthe first charater. (Classical Fortrans on punchcards had a C in column 6 if I rember Right)

    The IF statement needs brackets around the the whole conditional expression.

    See EddieJ correct but lancoic reply.

Still have questions? Get your answers by asking now.