Skip to content

Instantly share code, notes, and snippets.

@meisterluk
Created February 24, 2020 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meisterluk/0dbc6e18bd0cc43e430b4f77003c48d4 to your computer and use it in GitHub Desktop.
Save meisterluk/0dbc6e18bd0cc43e430b4f77003c48d4 to your computer and use it in GitHub Desktop.
A looping device in plain Teχ
% Input: we define \loop to print some text the number of given times
\newcount\c%
\long\def\loop#1 for #2 times{
\c=#2\relax%
\begingroup%
\def\iterate{%
\ifnum\c>0 %
\advance\c by -1%
{#1}\par%
\iterate%
\fi%
}%
\iterate
\endgroup%
}
\loop
this sentence.
for 10 times
% Output: “this sentence.
% this sentence.
% this sentence.
% this sentence.
% this sentence.
% this sentence.
% this sentence.
% this sentence.
% this sentence.
% this sentence.”
% Input: We define \ifundefined to determine
% whether the inner macro \iterate propagated outside
{\tt iterate} is defined?
% via “Teχ by Topic” page 142
\def\ifundefined#1{\expandafter
\ifx\csname#1\endcsname\relax}
\ifundefined{iterate}No\else Yes\fi
% Output: Yes
%\iterate
%% fails with “Undefined control sequence.” though
\bye
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment