Fortran If-then-else 语句
if…then 语句后面可以跟一个可选的 else 语句,当逻辑表达式为 false 时执行。
if…then…else 语句的基本语法是:
if (logical expression) thenstatement(s)elseother_statement(s)end if
但是,如果为 if 块命名,则命名的 if-else 语句的语法如下:
[name:] if (logical expression) then! various statements. . .else!other statement(s). . .end if [name]
如果逻辑表达式的计算结果为 true,则 if…then 语句中的代码块将被执行,否则 else 块中的代码段将被执行。

program ifElseProgimplicit none! local variable declarationinteger :: a = 100! check the logical condition using if statementif (a < 20 ) then! if condition is true then print the followingprint*, "a is less than 20"elseprint*, "a is not less than 20"end ifprint*, "value of a is ", aend program ifElseProg
结果为:
a is not less than 20value of a is 100