004. exit
ing a do
loop#
topic: Loops
You exit
a loop as shown in the code below,
which accumulates the sums of squared integers until the sum exceeds 100.
implicit none
integer :: i,ssq
ssq = 0
i = 0
do
i = i+1
ssq = ssq + i**2
if (ssq > 100) exit
end do
print *, "sum of squares from 1 to ", i, " is", ssq
end
sum of squares from 1 to 7 is 140
You EXIT a loop as shown in the code below, which accumulates the sums of squared integers until the sum exceeds 100
— FortranTip (@fortrantip) December 17, 2021
implicit none
integer :: i,ssq
ssq = 0
i = 0
do
i = i+1
ssq = ssq + i**2
if (ssq > 100) exit
end do
print*,"sum of squares from 1 to ",i," is",ssq
end
- 1
Compiled using
GNU Fortran (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
with no flags