多重ループ構造の例
do i=AA,BB,CC
do j=XX,YY,ZZ
...
end do
end do
例.行列のかけ算
program main
!
! Sample program of double do-loop
! Cal. of C=A*B
!
implicit none
integer :: i,j,k
real :: sum, amat(2,2), bmat(2,2), cmat(2,2)
amat(1,1)=1.0
amat(1,2)=2.0
amat(2,1)=3.0
amat(2,2)=4.0
bmat(1,1)=5.0 ; bmat(1,2)=6.0
bmat(2,1)=7.0 ; bmat(2,2)=8.0
do i=1,2
do j=1,2
sum=0.0
do k=1,2
sum=sum+amat(i,k)*bmat(k,j)
end do
cmat(i,j)=sum
end do
end do
write(*,*) 'Matrix C'
write(*,*) cmat(1,1),cmat(1,2)
write(*,*) cmat(2,1),cmat(2,2)
end program main
実行結果