Difference between revisions of "Template:Loop/doc"

From blackwiki
Jump to navigation Jump to search
imported>Vanisaac
m (→‎See also: clean up per WP:CAT#T and WP:AWBREQ add template:Sandbox other)
 
(14 intermediate revisions by 11 users not shown)
Line 1: Line 1:
 
{{Documentation subpage}}
 
{{Documentation subpage}}
 
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
 
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
This template is used to produce a simple loop that can repeat up to 150 times. It is not a real loop; it works by conditionally repeating the string. It is a simple version of {{tl|For loop}}. To use it, enter:<br/>
+
{{high-risk|86842}}
<code><nowiki>{{loop|times to repeat|string}}</nowiki></code><br/>
+
{{lua|Module:String}}
If string contains an equals sign, you must put "|2=string" instead of "|string". Examples:
+
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.
*<code><nowiki>{{loop|4|n}}</nowiki></code> produces {{loop|4|n}}
+
 
*<code><nowiki>{{loop|25|test}}</nowiki></code> produces {{loop|25|test}}
+
== Usage ==
*<code><nowiki>{{#expr:2{{loop|50|*2}}}}</nowiki></code> produces {{#expr:2{{loop|50|*2}}}}
+
 
*<code><nowiki>{{loop|9|2==}}</nowiki></code> produces {{loop|9|2==}} (the "2=" must be present)
+
<pre>{{loop|times to repeat|string}}</pre>
*<code><nowiki>{{loop|3|{{CURRENTYEAR}}}}</nowiki></code> produces {{loop|3|{{CURRENTYEAR}}}}
+
 
*{{xpdop3p3c|loop|3|||ab}}
+
If '''string''' contains an equals sign, you must put "|2=string" instead of "|string".
 +
 
 +
== Examples ==
 +
 
 +
*<code><nowiki>{{loop|4|n}}</nowiki></code>
 +
;{{loop|4|n}}
 +
 
 +
 
 +
*<code><nowiki>{{loop|25|test}}</nowiki></code>
 +
;{{loop|25|test}}
 +
 
 +
 
 +
*<code><nowiki>{{#expr:2{{loop|50|*2}}}}</nowiki></code>
 +
;{{#expr:2{{loop|50|*2}}}}
 +
 
 +
 
 +
When the string being replicated includes "=", we have to precede the second parameter with "2=", or use {{tl|1==}}.
 +
* <code><nowiki>{{loop|9|2==}}</nowiki></code>  
 +
;{{loop|9|2==}}  
 +
 
 +
or:
 +
* <code><nowiki>{{loop|9|{{=}}}}</nowiki></code>
 +
;{{loop|9|{{=}}}}
 +
 
 +
 
 +
*<code><nowiki>{{loop|3|{{CURRENTYEAR}}}}</nowiki></code>
 +
;{{loop|3|{{CURRENTYEAR}}}}
 +
 
 +
<nowiki>*</nowiki> If string contains an equals sign, you must put '|2=string' instead of '|string'.
 +
 
 +
==Template data==
 +
{{TemplateDataHeader}}
 +
<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==
 
==See also==
*{{tiw|for loop}}
+
*{{lt|For loop}}
*{{tiw|repeat}}
+
*{{lt|Simple recursion}}
*{{tiw|simple recursion}}
 
  
<includeonly>
+
<includeonly>{{Sandbox other||
 
[[Category:Wikipedia formatting and function templates|{{PAGENAME}}]]
 
[[Category:Wikipedia formatting and function templates|{{PAGENAME}}]]
  
[[cs:Šablona:Loop]]
+
}}</includeonly>
[[dsb:Pśedłoga:Loop]]
 
[[eo:Ŝablono:Loop]]
 
[[es:Plantilla:Loop]]
 
[[eu:Txantiloi:Begizta]]
 
[[fr:Modèle:Loop]]
 
[[hsb:Předłoha:Loop]]
 
[[ia:Patrono:Loop]]
 
[[it:Template:Ciclo]]
 
[[is:Snið:Lykkja]]
 
[[ko:틀:순환]]
 
[[mk:Шаблон:Јамка]]
 
[[ja:Template:Loop]]
 
[[no:Mal:loop]]
 
[[nn:Mal:Loop]]
 
[[pt:Predefinição:Loop]]
 
[[sq:Stampa:Loop]]
 
[[sk:Šablóna:Loop]]
 
[[sl:Predloga:Zanka]]
 
[[sv:Mall:Loop]]
 
</includeonly>
 

Latest revision as of 00:19, 26 April 2020

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

  • {{loop|4|n}}
nnnn


  • {{loop|25|test}}
testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest


  • {{#expr:2{{loop|50|*2}}}}
2.2517998136852E+15


When the string being replicated includes "=", we have to precede the second parameter with "2=", or use {{=}}.

  • {{loop|9|2==}}
=========

or:

  • {{loop|9|{{=}}}}
=========


  • {{loop|3|{{CURRENTYEAR}}}}
202620262026

* If string contains an equals sign, you must put '|2=string' instead of '|string'.

Template data

This is the TemplateData documentation for this template used by VisualEditor and other tools; see the monthly parameter usage report for this template.

TemplateData for Loop

The template is used to produce a simple loop of repeated strings.

Template parameters

ParameterDescriptionTypeStatus
Number1

Number of times to repeat

Numberrequired
String2

The string to be repeated. Use {{=}} if the string contains an equals sign.

Stringrequired

See also