[Tex/LaTex] Algorithm2e package for loop increment

algorithm2eformatting

I could not find in the manual how to increment a for loop in the algorithm2e package.

I want to something like this:

for(i=0; i<10, i=i+2){
 do something;
}

Best Answer

Somehow algorithm2e has \KwTo but not \KwBy. It is easy to define it, however:

\documentclass{article}

\usepackage{algorithm2e}
\pagestyle{empty}
\SetKw{KwBy}{by}
\begin{document}
\begin{algorithm}
  \For{$i\gets0$ \KwTo $8$ \KwBy $2$}{
    Do something
    }
\end{algorithm}
\end{document}

enter image description here