Template:Loop/doc
This is a documentation subpage for Template:Loop. It contains usage information, categories and other content that is not part of the original template page. |
This template is used on approximately 99,000 pages and changes may be widely noticed. Test changes in the template's /sandbox or /testcases subpages, or in your own user subpage. Consider discussing changes on the talk page before implementing them. |
This template uses Lua: |
This template is used to produce a simple loop. It is based on Module:String, and there is no limit to the number of iterations it can perform.
Usage
{{loop|times to repeat|string}}
If string contains an equals sign, you must put "|2=string" instead of "|string".
Examples
Markup | Renders as |
---|---|
{{loop|4|n}} |
nnnn |
{{loop|25|test}} |
testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest |
{{#expr:2{{loop|50|*2}}}} |
2.2517998136852E+15 |
{{loop|3|{{CURRENTYEAR}}}} |
202220222022 |
When the string being replicated includes "=", we have to precede the second parameter with "2=", or use {{=}}.
Markup | Renders as |
---|---|
{{loop|9|2==}} |
========= |
{{loop|9|{{=}}}} |
========= |
Surrounding whitespace is always stripped; you must use {{#invoke:string|rep}} instead to preserve it.
Markup | Renders as |
---|---|
{{#invoke:String|rep| hello |3}} |
" hello hello hello " |
{{loop|3| hello }} |
"hellohellohello" |
Template data
TemplateData for Loop
The template is used to produce a simple loop of repeated strings.
Parameter | Description | Type | Status | |
---|---|---|---|---|
Number | 1 | Number of times to repeat | Number | required |
String | 2 | The string to be repeated. Use {{=}} if the string contains an equals sign. | String | required |
See also
- Template:For loop (edit | talk | history | links | watch | logs)
- Template:Simple recursion (edit | talk | history | links | watch | logs)