In plain TeX and in LaTeX, one can implement this using counters and `\ifnum` checks or `\loop\unless`. Some LaTeX packages even provide their own looping constructs, e.g. TikZ/PGF provides `\foreach`, `pstricks` provides `\psforeach`, `multido` provides `\multido`, etc. If your question specifically involves or , add that tag to your question along with this one.