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

  • Thread starter Thread starter onlybarca6
  • Start date Start date
  • Tags Tags
    Fortran
Click For Summary
The discussion revolves around creating a do-loop in Fortran to generate a series of values based on two variables, `level` and `step`. The user initially struggles with implementing the loop to print ten fields, each incrementing the previous value by `step`. The solution provided involves initializing a variable `value` with the sum of `level` and `step`, followed by a do-loop that iterates ten times. In each iteration, the current value is printed, and then updated by adding `step`. The user confirms that this solution works effectively for their needs.
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.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

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