do while(〜の間繰り返す)構造の例
do while(条件)
...
end do
または
do
if(否定条件) exit
...
end do
例.階乗の計算プログラム
program main
!
! Sample programf for DO ... END_DO iteration
! Cal. of N!=N*(N-1)*...*1
!
implicit none
integer :: n
integer :: factorial,counter
write(*,*) 'Input N'
write(*,*) 'N = ?'
read(*,*) n
factorial=1
counter=n
do while(counter>0)
factorial=factorial*counter
counter=counter-1
end do
write(*,*) factorial
end program main
例.階乗の計算プログラム(その2)
program main
!
! Sample programf for DO ... END_DO iteration
! Cal. of N!=N*(N-1)*...*1
!
implicit none
integer :: n
integer :: factorial,counter
write(*,*) 'Input N'
write(*,*) 'N = ?'
read(*,*) n
factorial=1
counter=n
do
if(counter==0) exit
factorial=factorial*counter
counter=counter-1
end do
write(*,*) factorial
end program main
実行結果