About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Account
Latest news 2024-12-13: Ebook sale (12th December 2024 – 1st January 2025): cybercrime fiction short stories Unsocial Media and Smile for the Camera free; crime fiction short story The Briefcase free; short story noir crime fiction I’ve Heard the Mermaid Sing free; crime fiction novel The Private Enemy US$1.99; illustrated children’s story The Foolish Hedgehog US$0.99.


2.7.4 General Iteration with TeX's \loop

If you want a more general purpose way of repeating a block of code, you can use

\loopcode⟩\if… \repeat

This repeats ⟨code⟩ while the given condition is true. The \if… part should be one of TeX's conditionals, such as \ifnum, without the terminating \fi.

Example:

For example, to print the numbers from 1 to 10:

\newcount\mycount
\loop
 \advance\mycount by 1\relax
 \the\mycount.
\ifnum\mycount<10
\repeat

This produces:

1. 2. 3. 4. 5. 6. 7. 8. 9. 10.


This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-07-4).

© 2015 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs