目录

do while循环

当给定条件为真时,它重复一个陈述或一组陈述。 它在执行循环体之前测试条件。

语法 (Syntax)

do while (logical expr) 
   statements
end do

流程图 (Flow Diagram)

做的

例子 (Example)

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  

编译并执行上述代码时,会产生以下结果 -

2             1
3             2
4             6
5            24
6           120
7           720
8          5040
9         40320
10        362880
11       3628800
↑回到顶部↑
WIKI教程 @2018