Control Flow
If/Then/Else
Block Choice
An if (cond) then ... else ... end if block picks one branch. Comparisons return a logical value.
Program
Play the program to choose pass for a high score.
if_then_else.f90
program if_then_else
implicit none
integer :: score
character(len=8) :: grade
score = 82
if (score >= 80) then
grade = "pass"
else
grade = "retry"
end if
print '(A)', trim(grade)
end program if_then_else
if block
`if ... then ... else ... end if` chooses a branch.
logical
`score >= 80` evaluates to `.true.` or `.false.`.
trim
`trim` drops trailing blanks before printing.