How to print a line break in a loop in Plain TeX?

In plain.tex, \loop...\repeat is defined as:

\def\loop#1\repeat{\def\body{#1}\iterate}

so you cannot use \par inside it.

Also, in plain.tex, the \\ control sequence does not have the same "break line here" meaning as in LaTeX, so it doesn't work either.

You have two options:

First, redefine \loop...\repeat as a long macro:

\long\def\loop#1\repeat{\def\body{#1}\iterate}

so you can put \par in its argument.

Second, use \endgraf, which is exactly the same as TeX's primitive \par, except that when scanning the argument to a macro TeX looks for \par, but not \endgraf, so it can be used in these cases.


Have in mind that using \endgraf does a paragraph break, not a line break, as David said in the comments. Using \endgraf will insert a \parskip glue between each number. For an actual line break, see David's answer :)


\newcount\u\u1

\parindent0pt


\loop
    \the\u
    \ifnum\u<2
        \hfill\break
        \advance\u1
\repeat


\bye