Skip to content

superfluous-else-stop (S255)

Fix is sometimes available.

What it does

Checks for else statements with a stop statement in the preceeding if block

Why is this bad?

The else statement is not needed as the stop statement will always exit the parent function. Removing the else will reduce nesting and make the code more readable.

Example

integer function max(a, b):
  integer, intent(in) :: a, b
  if (a > b) then
    max = a
    stop
  else
    max = b
  end if
end function max

Use instead:

integer function max(a, b):
  integer, intent(in) :: a, b
  if (a > b) then
    max = a
    stop
  end if
  max = b
end function foo