Array sections let a program operate on part of an array without copying each element by hand.

Program

Play the program to choose how many leading values participate in the section sum.

array_section_sum.f90
program array_section_sum_demo
    implicit none
    integer :: values(5)
    integer :: count
    integer :: total

    values = [2, 4, 6, 8, 10]
    count = 
    total = sum(values(1:count))
    print '(I0)', total
end program array_section_sum_demo
program array_section_sum_demo
    implicit none
    integer :: values(5)
    integer :: count
    integer :: total

    values = [2, 4, 6, 8, 10]
    count = 
    total = sum(values(1:count))
    print '(I0)', total
end program array_section_sum_demo
program array_section_sum_demo
    implicit none
    integer :: values(5)
    integer :: count
    integer :: total

    values = [2, 4, 6, 8, 10]
    count = 
    total = sum(values(1:count))
    print '(I0)', total
end program array_section_sum_demo
section `values(1:count)` selects a contiguous part of the array.
sum `sum(section)` reduces the selected elements to one value.
bounds The section bounds are expressions, so a variable can choose the range.