018. Fortran has a one-line if
#
topic: Conditionals
In addition to if
-else if
, Fortran has a one-line if
:
if (condition) executable_statement
integer :: i
do i = -1, 1
if (i /= 0) print *, i, 1/i ! one-line if equivalent to below
if (i /= 0) then
print *, i, 1/i
end if
end do
end
-1 -1
-1 -1
1 1
1 1
In addition to if-elseif, Fortran has a one-line if:
— FortranTip (@fortrantip) December 19, 2021
if (condition) executable_statement
integer :: i
do i=-1,1
if (i /= 0) print*,i,1/i ! one-line if equivalent to below
if (i /= 0) then
print*,i,1/i
end if
end do
end
! output:
! -1 -1
! -1 -1
! 1 1
! 1 1
- 1
Compiled using
GNU Fortran (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
with no flags