How to Implement a Do-Loop for Incremental Calculations in Fortran?

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

The discussion focuses on implementing a do-loop in Fortran for incremental calculations using two variables: REAL :: level and step. The initial values are set to level = 2429.8 and step = 1159.8. The solution provided demonstrates how to print 10 fields by incrementally adding step to level within a do-loop. The final code snippet effectively outputs the desired results using the syntax do i = 1, 10 and updates the value variable accordingly.

PREREQUISITES
  • Basic understanding of Fortran programming language
  • Familiarity with variable declaration in Fortran
  • Knowledge of do-loops in Fortran
  • Experience with output statements in Fortran
NEXT STEPS
  • Study Fortran variable types and declarations
  • Learn more about Fortran control structures, specifically do-loops
  • Explore Fortran input/output operations for formatted data
  • Investigate advanced Fortran features such as array manipulation
USEFUL FOR

This discussion is beneficial for Fortran programmers, students learning Fortran, and developers looking to enhance their skills in performing iterative calculations within the language.

onlybarca6
Messages
5
Reaction score
0
I can't figure out how to make a do-loop in Fortran to do the following:

I have 2 variables. Let's say:

REAL :: level, step

level = 2429.8
step = 1159.8

and I need 10 fields printed out.

The first field will have the value:

level + step
<then the value of the one above + step>
<then the value of the one above + step>
<then the value of the one above + step>
<then the value of the one above + step>
<then the value of the one above + step>
<then the value of the one above + step>
<then the value of the one above + step>
<then the value of the one above + step>
<then the value of the one above + step>

So I'm sure it's simple but I can't figure out how to use the values of variables in do-loops instead of typing the numbers in.

Thanks in advance
 
Technology news on Phys.org
I'm a little rusty with Fortran, but this should do what you're asking.
Code:
value = level + step
do i = 1, 10
  write *,* value
  value = value + step
end do
 
Thanks so much! It works.
 

Similar threads

  • · Replies 25 ·
Replies
25
Views
4K
Replies
4
Views
4K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 37 ·
2
Replies
37
Views
5K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 59 ·
2
Replies
59
Views
12K