do ... if(条件) exit (...) end do例.自然数をその合計がNを超えるまで加えるプログラム
program main ! ! Sample program of DO ... END_DO ! Cal. of 1+2+3+... ! implicit none integer :: n integer :: sum,counter write(*,*) 'Input N' write(*,*) 'N = ?' read(*,*) n sum=0 counter=0 do counter=counter+1 sum=sum+counter if(sum>n) exit end do write(*,*) 'Sum up to',counter write(*,*) 'sum =',sum end program main実行結果