虽然标准的 Fortran90/95 没有直接的 DO WHILE 结构,但可以通过使用逻辑条件和 CYCLE 或EXIT 语句来实现类似的功能。Fortran2003 引入了 SELECT CASE 和DO CONCURRENT 等更高级的控制结构,但仍未直接引入 DO WHILE。不过,可以使用一个无限循环加上条件判断来模拟 DO WHILE。 program simulated_do_while_loop implic...
首先介绍do语句和do while语句的用法,它们的结构为, 它们经常配合 if 语句完成循环的任务, 输出结果: 和if 类似,do 之前也可以命名,方便在多层嵌套循环中离开某个循环。比如,有3层循环,从外到内分别为loop1, loop2, loop3,当 loop3 中满足某个条件时,代码需要离开loop2,但是留在 loop1 中。 假设有三层...
DO WHILE(逻辑表达式)...END DO 在新程序中不要使用DO WHILE循环,而使用更一般的当循环。3.1.3 ...
在Fortran中,循环结构主要通过do循环语句来实现。do循环语句有三种常见形式:do循环、do while循环和do until循环。这些循环结构都可以用来控制loop_time,即循环执行的次数。 1. do循环 do循环是Fortran中最常见的循环结构,用于指定循环次数。其语法形式如下: ```fortran do i = start, end, step !循环执行的语句...
do循环,Fortran中的循环可以加标签,如d前面的!interactive_loop就是标签! Prompt the user for radius and height and read them.write(*,*)'Enter radius and height.'!屏幕输出read (*,*,iostat=ierr) radius,height!键盘输入。isotat的值用判断输入成功否。! If radius and height could not be read ...
到底怎么跳? Fortran语法允许在do循环前命名,这样一来就比较好识别了。 下面举个例子。 一个二维数组每个元素都乘以2,到0元素时停止计算。 注意分别跳出loop_i和loop_j时m的不同。 跳出loop_i时,m = 2 跳出loop_j时,m = 3
在linux下的运行此程序时,只要在 do while 循环中加入一个输出语句 如 do while(flag)if(newloop==...
DO[s[,]]WHILE(e) Parameter Description s Label of an executable statement e Logical expression Description Execution proceeds as follows: The specified expression is evaluated. If the value of the expression is true, the statements in the range of theDO WHILEloop are executed. ...
If the value of the expression is true, the statements in the range of the DO WHILE loop are executed. If the value of the expression is false, control is transferred to the statement following the DO WHILE loop. Terminal StatementIf...
do while (counter<=limit) ans=ans+counter counter=counter+2 ! end do write(*,*) ans stop end 这个循环同样会执行5次,来仔细地看看这5次的过 程是怎么样的情况。 第1次: counter初值为2,所以counter<=limit成立,循环会执行 ans=ans+counter=0+2=2及 counter=counter+2=4+2=6 第2次: counter...