Fortran if-then 语句
if…then 语句由一个逻辑表达式和一个或多个语句组成,并以 end if 语句结束。
语法
if…then 语句的基本语法是:
if (logical expression) thenstatementend if
但是,您可以为 if 块命名,然后命名 if 语句的语法如下:
[name:] if (logical expression) then! various statements. . .end if [name]
如果逻辑表达式的计算结果为 true,则 if…then 语句中的代码块将被执行。如果逻辑表达式的计算结果为 false,则将执行 end if 语句后的第一组代码。

实例
program ifProgimplicit none! local variable declarationinteger :: a = 10! check the logical condition using if statementif (a < 20 ) then!if condition is true then print the followingprint*, "a is less than 20"end ifprint*, "value of a is ", aend program ifProg
结果如下:
a is less than 20value of a is 10
实例2
此实例演示了一个命名 if 块:
program markGradeAimplicit nonereal :: marks! assign marksmarks = 90.4! use an if statement to give gradegr: if (marks > 90.0) thenprint *, " Grade A"end if grend program markGradeA
结果为:
Grade A