Fortran do while 循环

当给定条件为 true 时,它会重复一个语句或一组语句。它在执行循环体之前测试条件。

语法
  1. do while (logical expr)
  2. statements
  3. end do
流程图

实例
  1. program factorial
  2. implicit none
  3. ! define variables
  4. integer :: nfact = 1
  5. integer :: n = 1
  6. ! compute factorials
  7. do while (n <= 10)
  8. nfact = nfact * n
  9. n = n + 1
  10. print*, n, " ", nfact
  11. end do
  12. end program factorial

结果为:

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

分类导航