# How may I remove \EndIf and \EndFor in algorithmicx?

For space consideration, I wish to condense my pseudocode.

I find it a bit annoying to me to always have a \EndIf or \EndFor at the end of every block, especially when inside the block only lies one statement. e.g.

\documentclass[a4paper]{article}

\usepackage{algorithmicx}
\usepackage{algorithm} % http://ctan.org/pkg/algorithms
\usepackage{algpseudocode} % http://ctan.org/pkg/algorithmicx
\newcommand*{\Let}[2]{\State #1 $\gets$ \parbox[t]{\linegoal}{#2\strut}}
\algnewcommand\algorithmicinput{\textbf{INPUT: }}
\algnewcommand\Input{\item[\algorithmicinput]}
\algnewcommand\algorithmicoutput{\textbf{OUTPUT: }}
\algnewcommand\Output{\item[\algorithmicoutput]}

\begin{document}
\begin{algorithm}
\begin{algorithmic}[1]
\Procedure{A}{}
\ForAll{$a\in A$}
\If{$a\geq b$}
\State\Return $a$
\EndIf
\EndFor
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}


To save the space, I wish to remove them, although it may be non-standard.

Once I do it, the code cannot be compiled due to errors.

Is there any "illegal" trick to kinda remove them from the output PDF?

-
Do you want to remove them from the tex file and/or from the output? – Andrew Swann Nov 19 '13 at 10:06
Please make your code compilable, starting with \documentclass{...} and ending with \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to help you. Help them help you: remove that one hurdle between you and a solution to your problem. – Jubobs Nov 19 '13 at 10:08
@AndrewSwann Output. Question updated. – Sibbs Gambling Nov 19 '13 at 10:14
@Jubobs Thanks for the advice. Corrected as suggested. – Sibbs Gambling Nov 19 '13 at 10:17
Doesn't loading the algpseudocode package with the noend option do the trick? – Jubobs Nov 19 '13 at 10:17

## Preventing end keywords from being typeset

Simply pass the noend option to the algpseudocode package: substitute \usepackage[noend]{algpseudocode} for \usepackage{algpseudocode} in your code and you get

## To avoid having to use \EndIf and \Endfor in your input file

(After clarification by the OP, this turns out to be off-topic.)

Missing \EndIf and \EndFor will generate errors; you cannot simply omit them in your input file. If you want to save yourself the hassle of having to use those macros in your input file in order to close control-flow statements, you can always define a macro that combines \If and \EndIf, another that combines \ForAll and \EndFor, etc.

\documentclass[a4paper]{article}

\usepackage{algorithmicx}
\usepackage{algorithm}
\usepackage{algpseudocode}
\newcommand*{\Let}[2]{\State #1 $\gets$ \parbox[t]{\linegoal}{#2\strut}}
\algnewcommand\algorithmicinput{\textbf{INPUT: }}
\algnewcommand\Input{\item[\algorithmicinput]}
\algnewcommand\algorithmicoutput{\textbf{OUTPUT: }}
\algnewcommand\Output{\item[\algorithmicoutput]}

\begin{document}
\newcommand\sForAll[2]{ \ForAll{#1}#2\EndFor} % snappy version of \ForAll...\EndFor
\newcommand\sIf[2]{ \If{#1}#2\EndIf}          % snappy version of \If...\EndIf

\begin{algorithm}
\begin{algorithmic}[1]
\Procedure{A}{}
\sForAll{$a\in A$}{
\sIf{$a\geq b$}{
\State\Return $a$
}
}
\EndProcedure
\end{algorithmic}
\end{algorithm}

\end{document}

-