# Real step-size in do loop-fortran

1. Mar 2, 2015

### Antonija

1. The problem statement, all variables and given/known data

I'm trying to find out is it possible to make a real do loop in fortran. As I read online, it's possible, and there is written how to do it but when I copy/paste it into my fortran editor, it' doesn't work.
At the moment I'm writing the code for minimize a function of a single variable, and one of the things I need is the real step do loop.

2. Relevant equations

3. The attempt at a solution
This is how my part of code looks like:

real:: a,b
real::delta=0.0001
do i=a,b, delta
variablesvalues(1)=x+(i-1)*delta
call {some function}
end do

and this is the code for which is written that it's example for real loop:
program xytab
implicit none
!constructs a table of z=x/y for values of x from 1 to 2 and
!y from 1 to 4 in steps of .5
real :: x, y, z
do x = 1,2
do y = 1,4,0.5
z = x/y
print *, x,y,z
end do
end do
end program xytab

in both examples I get the same error: Deleted feature: Step expression in DO loop at (1) must be integer.

I'm using Fortran 90.

Also, is it possible to have only step-size real, and other integer type?

2. Mar 2, 2015

### SteamKing

Staff Emeritus
There's a couple of things here.
1. If you're going to post source code, please use CODE tags to enclose the code. These allow for the preservation of spacing, etc. of the code as written by you.

2. In your variable declarations, you have declared a and b as real variables, but in the first DO-loop, the index variable i is assumed to be an INTEGER type (variables starting with I-N are automatically declared INTEGERs unless the program is otherwise instructed.), which is one reason why the compiler returns the error message.

3. In theory, real index variables for DO-loops may be programmed, but you should be careful using this approach. Floating point arithmetic always is subject to round-off error, so your real-valued DO-loops may not terminate properly when you expect them to.

3. Mar 2, 2015

### Staff: Mentor

In the Fortran 90 standard, do loops with real indices were declared obsolete, and eliminated in Fortran 95.

To the OP: loop with an integer index, and calculate the real equivalent inside the loop:
Code (Fortran):

do i = 1, 1000000
real_i = real(i) * 1e-5
...
end do

will loop from 1 to 10 in steps of 0.00001

4. Mar 2, 2015

### Antonija

Actually, at the moment I'm not sure if I have fortran 90 or fortran 95, because my linux crashed a month ago and then I had to build everything new... However, I tried it with do while loop and it worked....

It's like this:
Code (Text):
real:: a, x, delta= 0.0001
do while(x<=a)
x=x+delta
call [function]
...
end do