它重複語句或一組語句,當給定的條件為真。它測試的條件執行在迴圈體之前。
do while (logical expr) statements end 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