1

I have an algorithm which manipulates some local and global variables. I don't know the format to declare global variables, here I declared them in Require before the Procedure, However I think Require is for input parameters

\begin{algorithm}
\caption{An Algorithm}
\begin{algorithmic}
\Require
\State
    \State $A$, Global var1
    \State $B$, global var2
    \State $C$, global var3
\Procedure{Proc}{$input$}
 \State $D$, local var 
\State $A \gets B +D$
 \EndProcedure
\end{algorithmic}
\end{algorithm}

1 Answer 1

4

You can define a new block:

\documentclass{article}
\usepackage{algorithm,algpseudocode}

\algdef{SE}[VARIABLES]{Variables}{EndVariables}
   {\algorithmicvariables}
   {\algorithmicend\ \algorithmicvariables}
\algnewcommand{\algorithmicvariables}{\textbf{global variables}}

\begin{document}

\begin{algorithm}
\caption{An Algorithm}
\begin{algorithmic}
\Variables
 \State $A$, Global var1
 \State $B$, global var2
 \State $C$, global var3
\EndVariables
\Procedure{Proc}{$input$}
 \State $D$, local var
\State $A \gets B +D$
 \EndProcedure
\end{algorithmic}
\end{algorithm}

\end{document}

enter image description here

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.