TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The algorithmic package lets me make a while loop as

  \While{$u\neq v$}
    \State Something

which results in a

while(u is not v) do 
end while 

How can I make a do-while loop which result in

while(u is not v)

(Sorry for the lack of output. I don't know how to add that to my question. I hope the question and the intention is clear enough) I use document class memoir and packages algpseudocode and algorithm.

share|improve this question
There's a \Repeat <text> \Until{<condition>} construct, if that helps. Same meaning as do...while, just different words. – John Wickerson May 23 '13 at 9:03
@JohnWickerson Well, strictly speaking, those two constructs do not have the same meaning, since, for the two loops to be equivalent, the condition used after "until" would have to be the negated version of that used after "while". – Jubobs May 23 '13 at 9:35
Whoops! Good spot :) – John Wickerson May 23 '13 at 10:12
up vote 12 down vote accepted

You have to define the do-while construct yourself; see below.

Note: you tagged your question with algorithmicx, not algorithmic, so I produced an answer using the algorithmicx package.

enter image description here


\algdef{SE}[DOWHILE]{Do}{doWhile}{\algorithmicdo}[1]{\algorithmicwhile\ #1}%

    \State Something
  \doWhile{$u \neq v$} % <--- use \doWhile for the "while" at the end
share|improve this answer

protected by Community Jan 12 '15 at 12:58

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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