014. if
-else if
-end if
block#
topic: Conditionals
integer :: i
do i = -1, 1
print *, i
if (i < 0) then
print *, "negative"
else if (i == 0) then
print *, "zero"
else
print *, "positive"
end if
end do
end
-1
negative
0
zero
1
positive
If-elseif-endif block:
— FortranTip (@fortrantip) December 18, 2021
integer :: i
do i=-1,1
print*,i
if (i < 0) then
print*,"negative"
else if (i == 0) then
print*,"zero"
else
print*,"positive"
end if
end do
end
- 1
Compiled using
GNU Fortran (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
with no flags