1. IF-THEN语句 IF-THEN语句是Fortran中最基本的判断语句,它的语法如下: IF (condition) THEN statement block END IF 其中,condition是一个逻辑表达式,如果为真,则执行statement block中的语句,否则跳过该语句块。 2. IF-THEN-ELSE语句 IF-THEN-ELSE语句是IF-THEN语句的扩展版本,它的语法如下: IF (condition...
1.if...then 这是最简单的if语句结构。 if...then的语句结构如下: if (logical expression) then statement endif 还可以对if块进行命名: [name:] if (logical expression) then ! various statements . . . 2.if...then...elseif...then...else语句的基本语法如下: if (logical expression) then sta...
2.2.2 ELSE和ELSE IF子句 结构形式:IF(logical_expr1)THENStatement1Statement2...ELSE IF(logical_...
If-Else Statement:条件判断。 if (condition) then ! executable statements else if (another_condition) then ! other executable statements else ! else executable statements end if Do Loop:固定次数的循环。 do i = 1, 10 ! executable statements end do While Loop:基于条件的循环。 do while (...
If (logical-expression)then statement-1 . . statement-n else statement-1' . . statement-n' endif 上述的意思是If中的逻辑为真时则执行1至n这一组程序,不然则执行1'至n'这一组程序。若将一组程序简称为block,当上述的逻辑判断较为复杂时,常无法在一个条件中表达完成,故可有以下之另外两种形式:第一...
1program odd_num23implicitnone4integer :: num,num_odd5print *,'Input data number:'6read *,num78num_odd =0910do11num = num -11213if(num<0) then14exit15elseif (mod(num,2)==0) then16cycle17else18num_odd = num_odd +119endif202122print *, num23enddo2425print *,'The number of od...
statement block … END IF 其中,statement block表示一段代码段,它可能是单个语句,也可能是多个语句的组合。在if-then语句中,如果If后面的布尔表达式为真,就会执行Then语句块中的所有语句,在Then语句块执行完毕后,程序会跳过Else语句块,并继续执行后面的代码;如果If后面的布尔表达式为假,就会跳过Then语句块,执行Else...
num = num - 1 12 13 if (num<0) then 14 exit 15 elseif (mod(num,2)==0) then 16 cycle 17 else 18 num_odd = num_odd + 1 19 endif 20 21 22 print *, num 23 enddo 24 25 print *, 'The number of odd number is',num_odd 26 27 pause 28 29 end 如果输入20,输出结果为:...
倒数第三个endif 去掉,最后一个endif后再加一个endif.
name]END DO[name]![name:]DOindex=istart,iend,incrstatement...IF(逻辑表达式)CYCLE[name]...IF...