How to put multiple paragraphs in single \loop … \repeat

I wanted to create list of n Fibonaci numbers. This is my code so far:

\newcount\n
\n=5

\newcount\a
\newcount\b
\newcount\i
\a = 1
\b = 1
\i = 0

$a = \the\a$ \par
$b = \the\b$ \par
$i = \the\i$ \par
\vskip 15mm
\hrule
\loop
$\the\b$
\multiply\a by -1
\ifnum\i<\n
\repeat
\bye


I'd like to have all numbers on a separate lines but TeX doesn't allow \par in \loop ... \repeat construction. Do you have any idea how to achieve this?

Thanks for any directions.

• Just use \endgraf: $\the\b$\endgraf. \par wouldn't work because \loop is not a \long macro, but \endgraf does the same, with other name. – Phelype Oleinik Oct 10 '18 at 14:19

\endgraf is a renamed \par for such use:

\newcount\n
\n=5

\newcount\a
\newcount\b
\newcount\i
\a = 1
\b = 1
\i = 0

$a = \the\a$ \par
$b = \the\b$ \par
$i = \the\i$ \par
\vskip 15mm
\hrule
\loop
$\the\b$
\endgraf
\multiply\a by -1
\ifnum\i<\n
\repeat
\bye

• or you could copy the definition of \loop from latex, which would allow a blank line or \par – David Carlisle Oct 10 '18 at 14:22

In your case you could also put the loop in a group with obeylines. This command turns lines of input into lines that are typeset as a line. It should be used inside a group to limit its scope.

\newcount\n
\n=5

\newcount\a
\newcount\b
\newcount\i
\a = 1
\b = 1
\i = 0

$a = \the\a$ \par
$b = \the\b$ \par
$i = \the\i$ \par
\vskip 15mm
\hrule
{\obeylines
\loop
$\the\b$
\multiply\a by -1
\ifnum\i<\n
\repeat
\par}
\bye


The group allows to implement the loop in a more efficient way if you need higher values for \n than 5. (The value of \n is restored at the end of the group.)

{\obeylines
\i=\n
\loop
\n=\b