An allocatable object has to be allocated before accessing the elements, i.e.
allocate( ARR(100) ) ! dimensions ARR to 100 elements
do A = 1, 100
ARR(A) = 2*A
This is the explicit allocation.
There also exists the "allocation of assignment" feature: if the expression on the RHS (right-hand side) is an array of the same rank (and of a compatible type), then the allocatable array on the LHS is automatically allocated with the size of the RHS.
In your particular case the RHS could be an array constructor [...]
containing an implied-do loop:
ARR = [ (A*2, A=1,100) ] ! ARR is automatically allocated without
! needing allocate( ARR(100) ) first
Note that the allocation on assignment only works if the LHS is the full array and not an array section:
ARR(:) = [ (A*2, A=1,100) ] ! doesn't work if ARR is not already allocated
Note also that the "allocation on assignment" feature is also a "reallocation on assignment" feature: if the LHS allocatable array is already allocated with a size that differs from the size of the RHS, then it is deallocated first and reallocated with the new size. This for instance makes possible to build the array by iteratively appending one element at a time (the array has to be initially allocated to an empty array):
allocate( ARR(0) ) ! or ARR = [integer::]
do A = 1, 100
ARR = [ ARR, A*2 ]
end do
This approach is highly inefficient in terms of performance, though.