Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Two Questions About Fortran:

  1. Mar 24, 2010 #1
    Is it possible to loop a set of numbers?

    For example I wish to run a set of number 1,2,3,4,5.....52 but when we get to 52 I wish to go back to 1 and start looping again.

    How do write an output file in Fortran?

    I have opened a file and moved each character so that each letter has moved for example d to e.....x to y..... How could I write this new series of characters to a file
  2. jcsd
  3. Mar 25, 2010 #2


    User Avatar
    Science Advisor

    Not sure what you mean by "run" a set of numbers. If you just wish to print them, then something easy enough like this should work:
    Code (Text):

    do i=1,n !-- number of times you wish you loop
     do j=1,52
        write(6,*) j
     end do
    end do
    As far as the second question, you might be best parsing each character in a line, and then concatenating them all to one text string and writing that entire line to file (rather than character by character).
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook