9

I'm using algorithm package for writing algorithms. I'm using following code for generating a loop

\begin{algorithm}
\caption{My algorithm}\label{alg:myalgo}
\begin{algorithmic}[1]
\Procedure{Algo1}{}
\For{\texttt{<condition>}}
        \State \texttt{<my stuff>}
      \EndFor
\EndProcedure
\end{algorithmic}
\end{algorithm}

This code on compilation gives the output

enter image description here

The problem with this output is it is not showing the end for after line 3 as shown in this example.

Could someone tell me what is the problem with the above code.

1

2 Answers 2

24

The only reason for not having the "end for" is that you are using the noend option when loading algpseudocode.

In fact, the following MWE

\documentclass{article}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\begin{document}
\begin{algorithm}
\caption{My algorithm}\label{alg:myalgo}
\begin{algorithmic}[1]
\Procedure{Algo1}{}
\For{\texttt{<condition>}}
        \State \texttt{<my stuff>}
      \EndFor
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document} 

gives

enter image description here

while, if you replace

\usepackage[noend]{algpseudocode}

with

\usepackage{algpseudocode}

you obtain

enter image description here

0
1

Something like this. Need algpseudocode package.

enter image description here

Code

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\begin{document}

\begin{algorithm}
\caption{My algorithm}\label{alg:myalgo}
\begin{algorithmic}[1]
\Procedure{Algo1}{}
\For{\texttt{<condition>}}
        \State \texttt{<my stuff>}
      \EndFor
\EndProcedure
\end{algorithmic}
\end{algorithm}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.