xxxxxxxxxx
% in the header:
% \usepackage{algorithm}
% \usepackage{algpseudocode}
% in the body:
\begin{algorithm}
\caption{Euclid’s algorithm}
\label{euclid}
\begin{algorithmic}[1]
\Require $x\ge5$
\Ensure $x\le-5$
\Function{Euclid}{$a,b$}
\Comment{The g.c.d. of a and b}
\State $r\gets a\bmod b$
\While{$r \neq 0$}
\Comment{We have the answer if r is 0}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$
\EndWhile
\label{euclidendwhile}
\State \Return{$b$}
\Comment{The gcd is b}
\EndFunction
\end{algorithmic}
\end{algorithm}
xxxxxxxxxx
\usepackage{algorithm2e}
\begin{document}
\SetKwInOut{Object}{Object} %customized keywords
\SetKwInOut{Input}{Input} %customized keywords
\SetKwInOut{Output}{Output} %customized keywords
\SetKwInOut{Result}{Result} %customized keywords
\setlength{\algomargin}{1.5em}
\begin{algorithm}
\SetAlgoLined
\Object{My object}
\Input{My input}
\Output{My output}
\Result{The final result}
\While{condition}{
while-block\;
}
\end{algorithm}
\end{document}