Fortran do...while循環結構

它重複語句或一組語句,當給定的條件爲真。它測試的條件執行在循環體之前。

語法

do while (logical expr) statements end do

流程圖

do

示例

program factorial implicit none ! define variables
integer :: nfact = 1 integer :: n = 1 ! compute factorials do while (n <= 10) nfact = nfact * n
n = n + 1 print*, n, " ", nfact end do end program factorial

當上述代碼被編譯和執行時,它產生了以下結果:

1 1
2 2
3 6
4 24
5 120
6 720
7 5040
8 40320
9 362880
10 3628800