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

  • Thread starter Thread starter onlybarca6
  • Start date Start date
  • Tags Tags
    Fortran
AI Thread 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.
 
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
25
Views
3K
Replies
8
Views
4K
Replies
4
Views
2K
Replies
8
Views
4K
Replies
13
Views
2K
Replies
59
Views
11K
Back
Top