`block` syntax and my confusion

My earlier Euler program and one using BLOCK

program main
! simulate Euler's number e
implicit none
integer, parameter :: nsim = 10000000, niter = 10
integer            :: i,iter,nsum(nsim)
call random_seed()
do iter=1,niter
   do i=1,nsim
      block
         real    :: xsum,xran
         integer :: j
         xsum = 0.0
         j = 0
         do
            j = j + 1
            call random_number(xran)
            xsum = xsum + xran
            if (xsum > 1.0) exit
         end do
         nsum(i) = j
      end block
   end do
   print*,sum(nsum)/real(nsim),minval(nsum),maxval(nsum)
end do
print*,exp(1.0)," true"
end program main

take the same time using gfortran -O2.

2 Likes