009. Fortran array sections contain both endpoints#

topic: Arrays

Fortran array sections contain both endpoints like Julia, Matlab and R, unlike Python.

array-sections.f90 | | Godbolt Compiler Explorer logo | Fortran logo#
integer, parameter :: v(3) = [10, 20, 30]

print *, v(1:2)  ! output: 10 20
print *, v(:2)   ! 10 20
print *, v(2:3)  ! 20 30
print *, v(2:)   ! 20 30
print *, v(::2)  ! 10 30 -- stride of 2

end
Output1#
          10          20
          10          20
          20          30
          20          30
          10          30


1

Compiled using GNU Fortran (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 with no flags