Write an if-elseif block with algorithm2e without the final else

algorithm2e

I have an algorithm and an if-elseif block in it that does not have a final else. This leaves my algorithm open, I mean the algorithm does not show end after finishing elseif and it needs an \else to close it. But I do not have any else in the logic/procedure of my algorithm. Is there any solution to close it?

\documentclass{article} 
\usepackage{algorithm2e} 
\begin{document} 
\begin{algorithm} 
\raggedright 
\SetAlgoLined 
\LinesNumbered 
\SetKwProg{Function}{function}{}{end} 
\SetKwRepeat{Do}{do}{until}

$p \gets f(x)$\; 
\uIf{$p > 1$}{%   
$p \gets x $\; 
}
\uElseIf{$p < 0$}{% <--   
$p \gets -x $\; 
}

\Return $p$\;   
\end{algorithm} 
\end{document}

Best Answer

How about this (as suggested by Wille):

\documentclass{article}
\usepackage{algorithm2e}
\begin{document}
\begin{algorithm}
\raggedright
\SetAlgoLined
\LinesNumbered
\SetKwProg{Function}{function}{}{end}
\SetKwRepeat{Do}{do}{until}

$p \gets f(x)$\;
\uIf{$p > 1$}{%
  $p \gets x $\;
}\ElseIf{$p < 0$}{% <--
  $p \gets -x $\;
}

\Return $p$\;  
\end{algorithm}
\end{document}

enter image description here