Fortran Fortran: inner loop dependence on outer loop

  • Thread starter Thread starter svartak
  • Start date Start date
  • Tags Tags
    Fortran Loop
AI Thread Summary
The discussion revolves around writing nested loops in Fortran, specifically an outer loop indexed by 'm' and an inner loop indexed by 'n'. The outer loop iterates from 1 to Nmax, while the inner loop runs from 1 to Nmax-m. There is a query about directly specifying the range for 'n' and using the value of Nmax-m in calculations within the loops. The response confirms that this structure is valid in Fortran, indicating that modern compilers should handle it without issues, as long as they support versions beyond Fortran 66.
svartak
Messages
4
Reaction score
0
Hello,

I want to write an inner loop which takes values based on the variable values of the outer loop. For outer loop, m=1, Nmax and for inner loop, I want n to take values from 1 to Nmax-m. But I am not sure if I can directly specify n = 1, Nmax-m. Also I want to use Nmax-m value for one of the calculation inside the loop, how should I specify that?

Thanks a lot for your help,
Swati
 
Technology news on Phys.org
You mean
Code:
do m = 1, nmax
* calculate something
   do n = 1, nmax-m
*    calculate something else
   enddo 
enddo

Fortran won't have any problem with that (unless your compiler only understands Fortran 66, which is unlikely!)
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
8
Views
4K
Replies
6
Views
3K
Replies
16
Views
2K
Replies
8
Views
4K
Replies
25
Views
3K
Replies
2
Views
3K
Replies
8
Views
2K
Replies
13
Views
3K
Back
Top