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.

  • 6
    There's a \Repeat <text> \Until{<condition>} construct, if that helps. Same meaning as do...while, just different words. May 23, 2013 at 9:03
  • 2
    @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".
    – jub0bs
    May 23, 2013 at 9:35
  • 2
    Whoops! Good spot :) May 23, 2013 at 10:12

1 Answer 1


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
  • This breaks indentation very badly for me. The "while" is indented (bizarrely, along with its line number), and if the "do while" is included inside a different block, things get far worse (using some sort of absolute instead of relative indent, and messing up all blocks below the "do while"). I can't figure out how to use \algdef in general, are there examples anywhere? May 19, 2022 at 18:13
  • 1
    I found an easier way to do semantically the same thing: \Repeat \Until in the algpseudocodex package ctan.org/pkg/algpseudocodex?lang=en May 19, 2022 at 18:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .