Template:Loop/doc

{{high-use}}

{{Documentation subpage}}

{{lua|Module:String}}

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

class="wikitable"

! Code

! Output

{{loop|4|n}}

| {{loop|4|n}}

{{loop|25|test me}}

| {{loop|25|test me}}

{{#expr:2{{loop|50|*2}}}}

| {{#expr:2{{loop|50|*2}}}}

{{loop|3|{{CURRENTYEAR}}}}

| {{loop|3|{{CURRENTYEAR}}}}

{{loop|{{#expr:7*2}}|  '''MUDA}}!

| {{loop|{{#expr:7*2}}|  '''MUDA}}!

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

class="wikitable"

! Code

! Output

{{loop|9|2==}}

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

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

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

Surrounding whitespace is always stripped; you must use {{ml|string|rep|section=#rep}} instead to preserve it.

class="wikitable"

! Code

! Output

{{#invoke:String|rep| hello |3}}

| {{#invoke:String|rep| hello |3}}

{{loop|3| hello }}

| {{loop|3| hello }}

Template data

{{TemplateDataHeader}}

{

"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

}

}

}

See also

  • {{lt|For loop}}
  • {{lt|Simple recursion}}

{{Sandbox other||

Category:Repetition templates

}}