Doubt about variables declaration

Dear friends, I have a problem declaring an integer variable. A sketch of my code goes something like this:

implicit none
integer :: a(10), i
.
.
do i = 1, 10
a(i) = a(i - 1) + 2 ! where a(0) = 0
end do

However, I don’t know how to declare a(0) = 0, because when declaring it before the loop I get this error when compiling, " Array reference at (1) is out of bounds (0 < 1) in dimension 1."

Could you please help me fix this problem? Thank you very much.

Others can be more rigorous, but basically in Fortran the default lower bound of arrays is 1.

If you want, you can declare non-default bounds

 integer :: a(0:10)

@epagone, great solution, many thanks for the help.

You would still need an assignment “a(0)=0” before the loop.

Or the one liner “a=[ (2*i, i=0,10) ]”

or,

a = [ ( i, i = 0, 20, 2 ) ]

It avoids multiplication, though in this particular case, I think it is irrelevant.