Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
1  
Please add to your question a minimal, and compilable version of your code (including document class used, relevant packages involved, minimal example showing an algorithm). –  Gonzalo Medina Jun 27 '11 at 15:01
    
Welcome to TeX.sx! Please consider adding a minimal working example (MWE). –  Martin Scharrer Jun 27 '11 at 15:24
add comment

1 Answer 1

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

share|improve this answer
    
But \algloopdefx is not compatible with "algorithmic" package! –  Mohammad Jun 30 '11 at 8:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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