if / then / else
Try it yourself →Executes code based on a condition.
Syntax
if (condition) then ... else ... end if
Description
Condition inside parenthesis. Comparison == /= < > or .eq. .ne.; logic .and. .or. .not.
Example
program h
integer :: x
x = 7
if (mod(x,2) == 0) then
print *, "even"
else
print *, "odd"
end if
end program hExpected output
odd
When to use?
Flow branching.