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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.

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