This site is supported by donations to The OEIS Foundation.
Template:Repeat
[⧼Purge⧽ Template:Repeat]
The {{repeat}} typing-aid template repeats a given character string a specified number of times.
Usage
- {{repeat|nonnegative integer count|character string}}
where
- 1st argument: nonnegative integer count (required);
- 2 nd argument: character string to repeat (default is ∗, i.e. ∗).
Note: The MediaWiki parser always ignore initial and final whitespace (spaces, tabs, newlines) in template arguments. (So {{repeat|10|ab }}
is the same as {{repeat|10|ab}}
.)
Examples
Code Result {{tnxb|repeat|75}}
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ {{repeat|0|{{=}}}}
{{repeat|1|{{=}}}}
= {{repeat|10|{{=}}}}
========== {{repeat|25|{{=}}}}
========================= {{repeat|100|{{=}}}}
==================================================================================================== {{repeat|23|ab}}
ababababababababababababababababababababababab {{repeat|23|ab }}
ababababababababababababababababababababababab {{repeat|23|ab }}
ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab {{repeat|23|a b}}
a ba ba ba ba ba ba ba ba ba ba ba ba ba ba ba ba ba ba ba ba ba ba b {{repeat|250|.}}
.......................................................................................................................................................................................................................................................... {{repeat|50|⋅ - }}
⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ - ⋅ -
In the following, the vertical pipes are black (even though they appear greenish on some LCD monitors, either due to the monitor or due to an optical illusion...)
{{repeat|250|{{!}}}}
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
10 x = 2 x |
Code Result {{repeat|5|ln(10 * }} 1 {{repeat|5|)/ ln 2}}
ln(10 *ln(10 *ln(10 *ln(10 *ln(10 * 1 )/ ln 2)/ ln 2)/ ln 2)/ ln 2)/ ln 2 {{#expr: {{repeat| 0|ln(10*}}1{{repeat| 0|)/ ln 2}} }}
1 {{#expr: {{repeat| 1|ln(10*}}1{{repeat| 1|)/ ln 2}} }}
3.3219280948874 {{#expr: {{repeat| 2|ln(10*}}1{{repeat| 2|)/ ln 2}} }}
5.053948940532 {{#expr: {{repeat| 3|ln(10*}}1{{repeat| 3|)/ ln 2}} }}
5.6593391838607 {{#expr: {{repeat| 4|ln(10*}}1{{repeat| 4|)/ ln 2}} }}
5.8225617006257 {{#expr: {{repeat| 5|ln(10*}}1{{repeat| 5|)/ ln 2}} }}
5.8635821173811 {{#expr: {{repeat|10|ln(10*}}1{{repeat|10|)/ ln 2}} }}
5.8769986050183 {{#expr: {{repeat|15|ln(10*}}1{{repeat|15|)/ ln 2}} }}
5.8770105831049 {{#expr: {{repeat|20|ln(10*}}1{{repeat|20|)/ ln 2}} }}
5.8770105937826 {{#expr: {{repeat|25|ln(10*}}1{{repeat|25|)/ ln 2}} }}
5.8770105937921 {{#expr: {{repeat|30|ln(10*}}1{{repeat|30|)/ ln 2}} }}
5.8770105937921
Examples with invalid input
Code Result {{repeat|-1|a}} Repeat error: First argument must be a nonnegative integer {{repeat|13.5|a}} Repeat error: First argument must be a nonnegative integer {{repeat|a|10}} Repeat error: First argument must be a nonnegative integer
Tests
The code
-----
yields (interpreted by MediaWiki as an "horizontal rule" (<hr />
)
The code
{{repeat|5|-}}
yields (NOT interpreted)
-----
The code
*****
yields (* is interpreted by MediaWiki as a "list item" (<li>...</li>
) (preceded by a bullet) of an unordered list)
The code
{{repeat|5|*}}
yields (using a low asterisk ∗ ∗
instead of an asterisk * *
to avoid the MediaWiki interpretation of * as a "list item" (<li>...</li>
) (preceded by a bullet) of an unordered list)
∗∗∗∗∗
Code
Uses {{~Repeat~1}} and {{~Repeat~0}}.
Note that ∗ as default value for second argument is given by the ∗
named character entity.
<noinclude>{{documentation}}<!-- Put a null space {{sp|0}} before - (hyphen) to prevent the MediaWiki interpretation (when at beginning of a line) as an "horizontal rule" (<hr />). Replace * (asterisk) by ∗ because MediaWiki interprets * as a "list item" (<li>...</li>) (preceded with a bullet) for an unordered list. --></noinclude><includeonly>{{#if: {{{2|∗}}} | {{ifint| {{{1|not integer}}} | {{#ifeq: {{{2|∗}}} |-|{{sp|0}}}}<!-- -->{{#ifexpr: ( {{{1}}} ) >= 0 | {{~Repeat~1| {{#expr: (( {{{1}}} ) - ( {{{1}}} ) mod 400) / 400 }} |{{~Repeat~1| 400 |{{{2|∗}}}}}}}{{~Repeat~1| {{#expr: ( {{{1}}} ) mod 400}} |{{#ifeq:{{{2|∗}}}|*|∗|{{{2|∗}}}}}}} | {{error| Repeat error: First argument must be a [[Nonnegative integers|nonnegative integer]] }} }} | {{error| Repeat error: First argument must be a [[Nonnegative integers|nonnegative integer]] }} }} | <!-- no character to repeat! --> }}</includeonly>
See also
- {{loop}}
- {{for loop}}
- {{simple recursion}}
- {{repeat}}