I'm reading Malcolm Clark's A Plain TeX Primer. On page 111 there's an exercise to define a macro that prints the current time. I've reproduced Clark's answer below:
\divide\timehour by60 %gives 24 hour part of clock
\multiply\minleft by-60 %
\advance\minleft by\time %minutes after hour
My problem is that I don't know what
\relax is doing in lines 8 and 10 (after each
\fi). When I use this macro, it prints the time as it's supposed to:
If I delete the
\relax in line 8, I get the time but with the hour missing:
If I delete the
\relax in line 10 (and restore the
\relax in line 8), the macro works again like it did the first time:
I naively thought that the
\fi that ends the
\ifnum block ends the processing of whatever's going on in the
\ifnum ... \fi, and that it wouldn't matter whether
\relax is there or not, in either place. Clearly that's not the case, but I can't figure out what's happening in line 8, and also why the
\relax doesn't seem to be necessary in line 10.
In a different context the author does explain that
\relax is a "do nothing" command that (in this other context) prevents TeX from treating the expression before the
\relax and after the
\relax parts of the same expression. I get that. But concerning
\relax after an
\fi, he says:
\relax is probably not required, but it's always nice to have one in: perhaps an example of 'safe TeX'."
This might be good advice, but it is not enlightening.
I found the following questions about
\relax on tex.se, but I don't think they answer my question (or at least I'm not smart enough to figure it out):
So, what is
\relax actually doing in this macro?