Fortran: inner loop dependence on outer loop

  • Context: Fortran 
  • Thread starter Thread starter svartak
  • Start date Start date
  • Tags Tags
    Fortran Loop
Click For Summary
SUMMARY

The discussion focuses on implementing nested loops in Fortran, specifically how to define an inner loop that depends on the outer loop's variable. The outer loop iterates with the variable 'm' from 1 to 'Nmax', while the inner loop iterates with 'n' from 1 to 'Nmax-m'. The syntax provided is correct, and modern Fortran compilers will support this structure without issues, as long as they are not limited to Fortran 66.

PREREQUISITES
  • Understanding of Fortran syntax and loop structures
  • Familiarity with variable scope in programming
  • Knowledge of modern Fortran standards (Fortran 90 and above)
  • Basic concepts of algorithm design and nested loops
NEXT STEPS
  • Study Fortran loop constructs in detail, focusing on nested loops
  • Explore variable scope and lifetime in Fortran
  • Learn about performance considerations in nested loops in Fortran
  • Investigate compiler options for optimizing Fortran code
USEFUL FOR

This discussion is beneficial for Fortran developers, programmers working on scientific computing, and anyone looking to optimize nested loop structures in their Fortran applications.

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!)
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 25 ·
Replies
25
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 26 ·
Replies
26
Views
4K