[Tex/LaTex] algorithm2e: do N times

pseudocode

I want to write this in algorithm2e pseudocode:

Do N times
   stuff that has to be done N times
end

or maybe

Repeat N times
   stuff that has to be done N times
end

Since the loop body does not depend on a loop index, introducing one (like in a typical "for" loop) seems overkill.

My current best solution is

\For{$N$ times}{
  do stuff
}

but the output, "for N times do" is unclear.

(there are Do and Repeat commands in algorithm2e, but they both use end conditions: Do...while and Repeat...until, so not what I'm looking for.)

Best Answer

It seems there is no such built-in loop. Luckily, you can create your own! In algoritm2e, there are loops "with the condition at the start", or "with the condition at the end". To create your own "at the start" loop, do:

\SetKwFor{RepTimes}{repeat}{times}{end}

Then, to use it:

\RepTimes{100}{
    foobar
}

rendered latex image

Related Question