This site is supported by donations to The OEIS Foundation.
Template:~Loop~0
From OeisWiki
The following documentation is located at Template:~Loop~0/doc. [<Edit> Template:~Loop~0/doc]
[⧼Purge⧽ Template:~Loop~0]
[⧼Purge⧽ Template:~Loop~0]
The {{~Loop~0}} core function template, used by the {{Loop}} OEIS Wiki formatting and function template, repeatedly calls the named template (for which all arguments except the first must have default values) with its first argument ranging from offset to offset + (count - 1). If count is zero then the specified template (default is n) is not called. You may specify a separator string (default is empty string.)
Contents
Usage
- {{~Loop~0|nonnegative integer count|integer offset|name of template to call (default is n)|separator string (default is empty string)}}
Valid input
- 1st argument: nonnegative integer count in [0..64] (required)
- 2 nd argument: integer offset (required)
- 3 rd argument: name of template to call (default is n) (Cf. template {{n}}, which simply returns its first argument)
- 4th argument: separator string (default is empty string)
Examples
Examples with valid input
- :<span style="font-size: 11px;">{ {{~Loop~0|64|0|n|, }}, ... }</span>
gives
- { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, ... }
Code Result {{~Loop~0|0|10}} {{~Loop~0|1|10}} 10 {{~Loop~0|2|10}} 1011 {{~Loop~0|5|10}} 1011121314 {{~Loop~0|5|10|n}} 1011121314 {{~Loop~0|5|10|n|, }} 10, 11, 12, 13, 14 {{~Loop~0|10|0|Fibonacci}} 0112358132134 {{~Loop~0|10|5|Fibonacci}} 581321345589144233377 {{~Loop~0|10|5|Fibonacci|, }} 5, 8, 13, 21, 34, 55, 89, 144, 233, 377 {{~Loop~0|25|0|Fibonacci|, }} 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368 {{~Loop~0|25|0|Lucas|, }} 2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, 199, 322, 521, 843, 1364, 2207, 3571, 5778, 9349, 15127, 24476, 39603, 64079, 103682 {{~Loop~0|10|1|repeat| }} ∗ ∗∗ ∗∗∗ ∗∗∗∗ ∗∗∗∗∗ ∗∗∗∗∗∗ ∗∗∗∗∗∗∗ ∗∗∗∗∗∗∗∗ ∗∗∗∗∗∗∗∗∗ ∗∗∗∗∗∗∗∗∗∗
and
- :{{~Loop~0|10|1|repeat|<br />}}
gives
- ∗
∗∗
∗∗∗
∗∗∗∗
∗∗∗∗∗
∗∗∗∗∗∗
∗∗∗∗∗∗∗
∗∗∗∗∗∗∗∗
∗∗∗∗∗∗∗∗∗
∗∗∗∗∗∗∗∗∗∗
Examples with invalid input
Code Result {{~Loop~0|-1|10}} ~Loop~0 error: First argument (count) must be a nonnegative integer in [0..64] {{~Loop~0|65|10}} ~Loop~0 error: First argument (count) must be a nonnegative integer in [0..64] {{~Loop~0|a|10}} ~Loop~0 error: First argument (count) must be a nonnegative integer in [0..64] {{~Loop~0|3|b}} ~Loop~0 error: Second argument (offset) must be an integer
Code
{{ifint| {{{1|not an integer}}} | {{#ifexpr: ( {{{1}}} >= 0 ) and ( {{{1}}} <= 64 ) <!-- first argument is the count --> | {{ifint| {{{2|not an integer}}} <!-- second argument is the offset --> | <!-- * third argument is the name of the template to call (default is n) (template for which all arguments except the first have default values) * fourth argument is the separator string (default is the null string) -->{{#ifexpr:{{{1}}}>000|<!-- -->{{{{{3|n}}}|{{#expr: 000 + {{{2}}} }}}}}}<!-- -->{{#ifexpr:{{{1}}}>001|{{{4|}}}{{{{{3|n}}}|{{#expr: 001 + {{{2}}} }}}}}}<!-- -->{{#ifexpr:{{{1}}}>002|{{{4|}}}{{{{{3|n}}}|{{#expr: 002 + {{{2}}} }}}}}}<!-- -->{{#ifexpr:{{{1}}}>003|{{{4|}}}{{{{{3|n}}}|{{#expr: 003 + {{{2}}} }}}}}}<!-- (...) -->{{#ifexpr:{{{1}}}>060|{{{4|}}}{{{{{3|n}}}|{{#expr: 060 + {{{2}}} }}}}}}<!-- -->{{#ifexpr:{{{1}}}>061|{{{4|}}}{{{{{3|n}}}|{{#expr: 061 + {{{2}}} }}}}}}<!-- -->{{#ifexpr:{{{1}}}>062|{{{4|}}}{{{{{3|n}}}|{{#expr: 062 + {{{2}}} }}}}}}<!-- -->{{#ifexpr:{{{1}}}>063|{{{4|}}}{{{{{3|n}}}|{{#expr: 063 + {{{2}}} }}}}}}<!-- --> | {{error| ~Loop~0 error: Second argument (offset) must be an integer }} }} | {{error| ~Loop~0 error: First argument (count) must be a [[Nonnegative integers|nonnegative integer]] in [0..64] }} }} | {{error| ~Loop~0 error: First argument (count) must be a [[Nonnegative integers|nonnegative integer]] in [0..64] }} }}
See also
- {{loop}}
- {{for loop}}
- {{simple recursion}}
- {{repeat}}