# Nested If and For in algorithm2e

I have the following code in algorithm2e with boxruled, vlined, and linesnumbered options. pdflatex gives me an empty line at the end of both the for loops inside the ifs. Can someone please suggest a way to get rid of the extra lines? Thanks.

\If {$\lfloor c\ (\log (n+1) - \log n) \rfloor > 1$}
{
$u \leftarrow {\tt SampleControl}$\;
$U \leftarrow \{ u \} \cup U_m$\;
}
${\tt ConnectState}(z, S_{n+1}, U, P_n, Q_n, \delta_n)$\;
\eIf{$\min_{u \in U} \Delta t_{n+1} (z_{n+1}, u) \leq \delta_n$}
{   $\delta_{n+1} = \delta_n/2$\;
\For{$z \in S_{n+1}$}{
${\tt ConnectState}(z, S_{n+1}, U, P_{n+1}, Q_{n+1}, \delta_{n+1})$\;
}}{ $\delta_{n+1} \leftarrow \delta_n$\;
\For{$z' \in Z_\mathrm{near}(z_{n+1})$}{
${\tt ConnectState}(z', S_{n+1}, U, P_{n+1}, Q_{n+1}, \delta_{n+1})$\;
}}

-
Welcome to TeX.SX! Please, add a minimal preamble to your code so that it becomes a complete example that can be run through LaTeX. –  egreg Sep 16 '12 at 11:08

Perhaps you mean the additional vertical space at the end of the if and for blocks. It can be configured by \SetVlineSkip:

\documentclass{article}
\usepackage[boxruled,vlined,linesnumbered]{algorithm2e}

\SetVlineSkip{0pt}

\begin{document}

\begin{algorithm}
\caption{Caption of algorithm}
\If {$\lfloor c\ (\log (n+1) - \log n) \rfloor > 1$}
{
$u \leftarrow {\tt SampleControl}$\;
$U \leftarrow \{ u \} \cup U_m$\;
}
${\tt ConnectState}(z, S_{n+1}, U, P_n, Q_n, \delta_n)$\;
\eIf{$\min_{u \in U} \Delta t_{n+1} (z_{n+1}, u) \leq \delta_n$}
{   $\delta_{n+1} = \delta_n/2$\;
\For{$z \in S_{n+1}$}{
${\tt ConnectState}(z, S_{n+1}, U, P_{n+1}, Q_{n+1}, \delta_{n+1})$\;
}}{ $\delta_{n+1} \leftarrow \delta_n$\;
\For{$z' \in Z_\mathrm{near}(z_{n+1})$}{
${\tt ConnectState}(z', S_{n+1}, U, P_{n+1}, Q_{n+1}, \delta_{n+1})$\;
}}
\end{algorithm}

\end{document}


BTW, \SetVlineSkip is defined as:

\newcommand{\SetVlineSkip}[1]{\skiphlne=#1}%


A better definition for \SetVlineSkip would be (terminating of the assignment, support of package calc):

\renewcommand*{\SetVlineSkip}{\setlength{\skiphlne}}

-
Thanks a lot for your answer. I however just realised that the extra vspace shows up if I use \IncMargin{} in ieeeconf.cls. It does not show up in the article class. Any suggestions to get incmargin and still remove the white space? :) –  Pratik C Sep 17 '12 at 1:08
The class file is IEEEconf.cls. In twocolumn mode the line width is too small and you get overfull \hbox warnings. Fix them and then also the additional white space should disappear. –  Heiko Oberdiek Sep 17 '12 at 1:26
I solved this problem by reducing the font in the algorithm environment, saves more space for my paper and looks better as well! –  Pratik C Sep 29 '12 at 22:48