You can also do it in the following (not very efficient!) style:
\def\tick#1{\vrule height 0pt depth #1pt}
\def\tmp{\hbox to 1cm{\hfil\tick4\hfil\tick8}}
\def\doticks#1{\count255=#1\relax
\ifnum\count255=1
\tmp
\else
\advance \count255 by -1
\tmp\doticks{\count255 }%
\fi}
\def\ruler#1{\vbox{\hrule\hbox{\tick8\doticks{#1}}}}
\ruler{10}
\count255=5
\ruler{\count255}
\nopagenumbers
\bye

Actually, this code (maybe I should have read it) indeed does nest many \if..\fi
so to avoid that, one could do the (somewhat silly but working):
\def\doticks#1{\count255=#1\relax
\tmp
\ifnum\count255=1
\let\next\relax
\else
\def\next {\doticks{\count255 }}%
\advance \count255 by -1
\fi
\next }
Anyway, there is in the Plain format a loop which it is very natural to use here:
\def\tick#1{\vrule height 0pt depth #1pt}
\def\tmp{\hbox to 1cm{\hfil\tick4\hfil\tick8}}
\def\doticks #1{\count255=#1\relax
\loop
\tmp
\ifnum\count255>1
\advance\count255 by -1
\repeat
}
\def\ruler#1{\vbox{\hrule\hbox{\tick8\doticks{#1}}}}
\ruler{10}
\newcount\mycnt
\mycnt=10
\ruler{\mycnt}
\nopagenumbers
\bye

If one wants to preserve as egreg
the value stored in \count 255
one can also do it without creating a group. It is irrelevant for the task at hand, but for other situations it could be useful to not create a group.
(for efficiency one should also do as egreg
and use \count@
, @ne
, m@ne
etc...)
\def\tick#1{\vrule height 0pt depth #1pt}
\def\tmp{\hbox to 1cm{\hfil\tick4\hfil\tick8}}
\def\doticks #1{\edef\restorecountxxlv{\count255=\the\count255\relax}%
\count255=#1\relax \dotickticks \restorecountxxlv }
\def\dotickticks{\tmp
\ifnum\count255>1
\advance\count255 by -1
\expandafter\dotickticks
\fi }
\def\ruler#1{\vbox{\hrule\hbox{\tick8\doticks{#1}}}}
\count255 7
\ruler{10}
{\tt\string\count 255} stores \the\count255
\newcount\cnt
\cnt=3
\ruler{\cnt}
{\tt\string\count 255} stores \the\count255
\bye

\count255
because the TeXbook mentions that it is a scratch register. However I just tried Ian solution and replacing\mycount
with\count255
it doesn't work, so some macro in there is using\count255
too...\doticks
... which is necessary.\doticks{\number#1}
), there is also the%
in\def\doticks#1{\count255=#1%
which is problematic, because the\ifnum
test may be expanded before the assignment is done. If you do\expandafter\doticks\expandafter{\number#1}
on one hand and on the other hand\def\doticks#1{\count255=#1
without a%
(but with a space), the it will be ok. See my upcoming answer for the complete thing (there are other modifications too)