020. Loop variable after completion#

topic: Loops

The loop variable equals the upper bound plus the stride after normal completion of a loop.

loop-var.f90 | | Godbolt Compiler Explorer logo | Fortran logo#
integer :: i

do i = 1, 3
  if (i > 1) exit
end do
print *, i  ! 2

do i = 1, 3  ! stride of 1
  continue  ! placeholder
end do
print *, i  ! 4

do i = 1, 3, 2  ! stride of 2
  continue
end do
print *, i  ! 5

end
Output1#
           2
           4
           5


1

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