Template:Loop/doc: Difference between revisions
m 1 revision imported |
|
(No difference)
|
Latest revision as of 23:11, 5 January 2025
Warning | This template is used on approximately 107,000 pages. To avoid major disruption and server load, any changes should be tested in the template's /sandbox or /testcases subpages, or in your own user subpage. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
{{#ifeq:doc|doc|Template:Notice}}
File:Lua-Logo.svg | 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
<syntaxhighlight lang="wikitext">String Module Error: function rep expects a number as second parameter, received "times to repeat"</syntaxhighlight>
If string contains an equals sign, you must put "|2=string" instead of "|string".
Examples
Code | Output |
---|---|
<syntaxhighlight lang="wikitext" inline>nnnn</syntaxhighlight> | nnnn |
<syntaxhighlight lang="wikitext" inline>test metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest me</syntaxhighlight> | test metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest metest me |
<syntaxhighlight lang="wikitext" inline>{{#expr:2
|
{{#expr:2
|
<syntaxhighlight lang="wikitext" inline>202520252025</syntaxhighlight> | 202520252025 |
<syntaxhighlight lang="wikitext" inline>String Module Error: function rep expects a number as second parameter, received "{{#expr:7*2}}"!</syntaxhighlight> | String Module Error: function rep expects a number as second parameter, received "{{#expr:7*2}}"! |
When the string being replicated includes "=", we have to precede the second parameter with "<syntaxhighlight lang="wikitext" inline>2=</syntaxhighlight>", or use {{=}}.
Code | Output |
---|---|
<syntaxhighlight lang="wikitext" inline>=========</syntaxhighlight> | ========= |
<syntaxhighlight lang="wikitext" inline>=========</syntaxhighlight> | ========= |
Surrounding whitespace is always stripped; you must use {{#invoke:string|rep}} instead to preserve it.
Code | Output |
---|---|
<syntaxhighlight lang="wikitext" inline> hello hello hello </syntaxhighlight> | hello hello hello |
<syntaxhighlight lang="wikitext" inline>hellohellohello</syntaxhighlight> | hellohellohello |
Template data
|=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3ALoop%7CLoop%7CLoop%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}} |no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|no|S|s}}ee a monthly parameter usage report] for {{#if:Loop|Template:Loop|this template}} in articles{{#ifeq:{{safesubst:#switch: y
|no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|yes| based on {{#if:Loop|its|this}} TemplateData}}.
|None|none=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3ALoop%7CLoop%7CLoop%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}} |no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|no|P|p}}arameter usage report]{{#ifeq:{{safesubst:#switch: y
|no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|yes| based on {{#if:Loop|its|this}} TemplateData}}
|for|For=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3ALoop%7CLoop%7CLoop%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}} |no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|no|P|p}}arameter usage report] for {{#if:Loop|Template:Loop|Template:Loop}}{{#ifeq:{{safesubst:#switch: y
|no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|yes| based on {{#if:Loop|its|this}} TemplateData}}.
|#default=[1]{{#ifeq:{{safesubst:#switch: y |no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|yes| based on {{#if:Loop|its|this}} TemplateData}} }}|This is the {{#if:|TemplateData|TemplateData}} for this template used by TemplateWizard, VisualEditor and other tools. {{#switch:
|=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3ALoop%7CLoop%7CLoop%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}} |no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|no|S|s}}ee a monthly parameter usage report] for {{#if:Loop|Template:Loop|this template}} in articles{{#ifeq:{{safesubst:#switch: y
|no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|yes| based on {{#if:Loop|its|this}} TemplateData}}.
|None|none=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3ALoop%7CLoop%7CLoop%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}} |no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|no|P|p}}arameter usage report]{{#ifeq:{{safesubst:#switch: y
|no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|yes| based on {{#if:Loop|its|this}} TemplateData}}
|for|For=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3ALoop%7CLoop%7CLoop%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}} |no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|no|P|p}}arameter usage report] for {{#if:Loop|Template:Loop|Template:Loop}}{{#ifeq:{{safesubst:#switch: y
|no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|yes| based on {{#if:Loop|its|this}} TemplateData}}.
|#default=[2]{{#ifeq:{{safesubst:#switch: y |no |n |f |false |off |0 = no | = no |¬ = no |yes |y |t |true |on |1 = yes |#default = no
}}|yes| based on {{#if:Loop|its|this}} TemplateData}} }}}}
TemplateData for Loop
{{#switch:
{{#if: | {{{demospace}}} | {{#ifeq:Template|Template | template | other }} }}
| template = {{#if:{{#ifeq:doc|sandbox|1}}{{#ifeq:doc|doc|1}}||
}} | other | #default = }} <templatedata> {
"description": "The template is used to produce a simple loop of repeated strings.", "params": { "1": { "label": "Number", "description": "Number of times to repeat", "type": "number", "required": true }, "2": { "label": "String", "description": "The string to be repeated. Use = if the string contains an equals sign.", "type": "string", "required": true } }
} </templatedata>
See also
- Template:For loop ({{#if:||edit |}} {{#if:||talk |}} {{#if:||history |}} {{#if:||links |}} {{#if:||watch |}} {{#if:||logs}})
- Template:Simple recursion ({{#if:||edit |}} {{#if:||talk |}} {{#if:||history |}} {{#if:||links |}} {{#if:||watch |}} {{#if:||logs}})