4

for example we have three nested loop

\FORALL{ condition 1}
            \FORALL{condition 2}
                 \FORALL{condition 3}
                \STATE {do sth}
                  \ENDFOR
             \ENDFOR
          \ENDFOR

if we use [noend] to be false then print 3 "endif" but I want to print only one, the first loop only!!

Does anybody has experiences?

4

Seeing the syntax of your code snippet, I assume that you are using the algorithmic package. You should use the algorithmicx (with a trailing "x") instead; this package offers you many possibilities to customize the layout of algorithms and allows you to define a completely new layout for your specific needs.

In the following example code I show three variations on the same "algorithm"; the first one, shoes the standard behaviour (the three "forall-loops" with their corresponding "end for"). In the second one, I used \algnotext to suppress all the "end for" sentences. In the third one I used a custom-defined "forall" loop which doesn't produce any ending text; this, combined with the standard \ForAll, \EndFor construct, will produce the desired result:

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

\algloopdefx{NFor}[1]{\textbf{for all} #1 \textbf{do}}

\begin{document}

Each \texttt{for} with its corresponding ending:
\begin{algorithmic}
  \ForAll{ condition 1}
    \ForAll{condition 2}
      \ForAll{condition 3}
        \State{do sth}
      \EndFor
    \EndFor
  \EndFor
\end{algorithmic}

Using \verb+\algnotext+ to suppress the ending part for every \verb+\EndFor+ command:
\begin{algorithmic}
  \algnotext{EndFor}
  \ForAll{ condition 1}
    \ForAll{condition 2}
      \ForAll{condition 3}
        \State{do sth}
      \EndFor
    \EndFor
  \EndFor
\end{algorithmic}

Using the newly defined loop-block to suppress the ending part at will:
\begin{algorithmic}
  \ForAll{ condition 1}
    \NFor{condition 2}
      \NFor{condition 3}
        \State{do sth}
  \EndFor
\end{algorithmic}

\end{document}

enter image description here

  • But \algloopdefx is not compatible with "algorithmic" package! – Mohammad Jun 30 '11 at 8:49

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.