In Fortran, you can use nested IF statements to create conditional structures with multiple levels of branching.
Each nested IF statement is evaluated based on the outcome of the previous condition.
Here’s an example of nested IF statements in Fortran:
program NestedIfExample
implicit none
integer :: x
x = 10
if (x > 0) then
write(*,*) "x is positive."
if (x > 5) then
write(*,*) "x is greater than 5."
if (x > 7) then
write(*,*) "x is greater than 7."
else
write(*,*) "x is not greater than 7."
end if
else
write(*,*) "x is not greater than 5."
end if
else
write(*,*) "x is non-positive."
end if
end program NestedIfExample