[Tex/LaTex] How to format “for loop” for printing a (pseudo) code listing

algorithms

I want to write a 'for' statement, but unsure how to do this with LaTeX. What I am trying to do is:

for k = 1, k++, while k < i

What is the proper (or at least a decent way) to write this in LaTeX?

Let me re-phrase:

I do not want to actually create a loop, I just want to print a line that will be the text of the beginning of a for-loop. I'm unsure how to do this.

Best Answer

If you just want to print the statement, then something like

\[
\text{for $k = 1$, $k{+}{+}$, while $k < i$}
\]

will set it in a displayed format (remember to call \usepackage{amsmath} in the preamble). If it's as an item in an enumerate, then

\item for $k = 1$, $k{+}{+}$, while $k < i$

is sufficient.

The only subtle point is to enclose the + symbols between braces, in order to avoid undesired spacings.