Template talk:Loop
Template:Loop is permanently protected from editing because it is a heavily used or highly visible template. Substantial changes should first be proposed and discussed here on this page. If the proposal is uncontroversial or has been discussed and is supported by consensus, editors may use {{edit template-protected}} to notify an administrator or template editor to make the requested edit. Usually, any contributor may edit the template's documentation to add usage notes or categories.
Any contributor may edit the template's sandbox. Functionality of the template can be checked using test cases. |
Question
[edit]What is the difference between this template and {{Loop1}}?—Ëzhiki (Igels Hérissonovich Ïzhakoff-Amursky) • (yo?); 16:03, 23 March 2007 (UTC)
QUESTION
[edit]Where do you type it in? —Preceding unsigned comment added by 76.126.233.15 (talk) 03:18, 1 May 2008 (UTC)
Preprocessor
[edit]Does this template still work with the new preprocessor? I know {{for loop}} doesn't. Thanks. Verisimilus T 00:13, 28 January 2008 (UTC)
- Yes, it does.--Patrick (talk) 13:52, 28 January 2008 (UTC)
Why do you need to double?
[edit]The current version has the following lines:
-->{{#ifexpr:({{{1}}}*2-xxx)>xxx|{{{2}}}}}<!--
where xxx is a number. Why do you need the "*2"?
Can you use just the following?
-->{{#ifexpr:({{{1}}})>xxx|{{{2}}}}}<!--
- TAKASUGI Shinji (talk) 12:58, 29 February 2008 (UTC)
- Yes, the *2 does not seem needed.--Patrick (talk) 08:33, 1 May 2008 (UTC)
The subtraction stuff was originally added in this edit in the creator's sandbox. I'm also confused as to why this was done. --- RockMFR 21:31, 9 May 2008 (UTC)
- May be I can find some reason for it: it is for correct rounding to the nearest integer for testing.
- Anyway, rounding could be simpler, because the tested limits are known (you just need to test if higher than the limit minus 0.5, so you could replace
-->{{#ifexpr:({{{1}}}*2-032>032|{{{2}}}}}<!--
- by
-->{{#ifexpr:({{{1}}})>031.5|{{{2}}}}}<!--
- Also: don't nest the various #if tests (even if you think this could be a good idea, this is not as explained below), otherwise it will easily exhaust a limit in the preprocessor (too many nested levels) in the various pages or templates where this {{loop}} template is used, typically through {{spaces}}.
- Note that nesting #if does not save resources during the expansion of templates, because all parameters of templates or parser functions are evaluated recursively, even if they are finally dropped: this would cause the parameter size of the outer level to explode and being copied/reevaluated multiple times during the expansion, consuming too much memory (this is the most probable reason why the maximum nesting level limit was implemented).
- As a rationale, remember to avoid to heavy nesting of templates and parser functions. Note that even if MediaWiki forbids recursing macros, it tolerates it only for parser functions like #if, and this is certainly a place where MediaWiki should be imporoved (so that no more nesting level limit would be needed for parser functions:
- The preprocessor still does not use a lazy evaluation of parameters until they are really needed (parameters that will not need to be fully evaluated are those eliminated by #if and #switch parser functions). Using lazy evaluation would really speed up the rendering in MediaWiki, and save lots of memory ressources.
- 90.45.93.218 (talk) 23:05, 24 June 2008 (UTC)
Edit request
[edit]Please update {{/doc}} with {{documentation}}. Per Wikipedia:Template documentation/List Thankyou. -- ṃ•α•Ł•ṭ•ʰ•Ə•Щ• @ 06:13, 28 April 2008 (UTC)
- Done.--Patrick (talk) 07:23, 28 April 2008 (UTC)
Is there any way to call loop as an inner template?
[edit]is there any way to call loop as an inner template? ie:
{{loop |{{{1}}}|abc}}
where the number of loop reiterations is passed by the outer template? I get this "Expression error: Unrecognised punctuation character "{"" when I try it. Thanks. --stmrlbs|talk 07:04, 3 August 2009 (UTC)
- That should work, can you give a link to your attempt?--Patrick (talk) 07:40, 11 September 2009 (UTC)
Edit request from Joeytje50, 21 November 2010
[edit]{{edit protected}}
I made this on the RuneScape Wiki, and it works until 1399 times instead of 149 times. Also it is a shorter code.
Show code |
---|
This is for 1399 repeatings as a limit:
{{#ifexpr:({{{2|2}}}<=10)=1|{{Multi/1|{{{1}}}|{{{2|2}}}}}|{{Multi/1|{{{1}}}|{{#expr:{{{2|2}}}-({{#expr:floor({{{2|2}}}/10) round 0}}*10)}}}}<!-- -->{{Multi/1|{{Multi/1|{{{1}}}|10}}|{{#ifexpr:({{{2|2}}}>100)=1|{{#expr:{{#expr:floor({{{2|2}}}/10) round 0}}-({{#expr:floor({{{2|2}}}/100) round 0}}*10)}}|{{#expr:floor({{{2|2}}}/10) round 0}}}}}}<!-- -->{{#ifexpr:({{{2|2}}}>100)=1|{{Multi/1|{{Multi/1|{{{1}}}|10}}|10}}|}}<!-- -->{{#ifexpr:({{{2|2}}}>200)=1|{{Multi/1|{{Multi/1|{{{1}}}|10}}|10}}|}}<!-- -->{{#ifexpr:({{{2|2}}}>300)=1|{{Multi/1|{{Multi/1|{{{1}}}|10}}|10}}|}}<!-- -->{{#ifexpr:({{{2|2}}}>400)=1|{{Multi/1|{{Multi/1|{{{1}}}|10}}|10}}|}}<!-- -->{{#ifexpr:({{{2|2}}}>500)=1|{{Multi/1|{{Multi/1|{{{1}}}|10}}|10}}|}}<!-- -->{{#ifexpr:({{{2|2}}}>600)=1|{{Multi/1|{{Multi/1|{{{1}}}|10}}|10}}|}}<!-- -->{{#ifexpr:({{{2|2}}}>700)=1|{{Multi/1|{{Multi/1|{{{1}}}|10}}|10}}|}}<!-- -->{{#ifexpr:({{{2|2}}}>800)=1|{{Multi/1|{{Multi/1|{{{1}}}|10}}|10}}|}}<!-- -->{{#ifexpr:({{{2|2}}}>900)=1|{{Multi/1|{{Multi/1|{{{1}}}|10}}|10}}|}}<!-- -->{{#ifexpr:({{{2|2}}}>1000)=1|{{Multi/1|{{Multi/1|{{{1}}}|10}}|10}}|}}<!-- -->{{#ifexpr:({{{2|2}}}>1100)=1|{{Multi/1|{{Multi/1|{{{1}}}|10}}|10}}|}}<!-- -->{{#ifexpr:({{{2|2}}}>1200)=1|{{Multi/1|{{Multi/1|{{{1}}}|10}}|10}}|}}<!-- -->{{#ifexpr:({{{2|2}}}>1300)=1|{{Multi/1|{{Multi/1|{{{1}}}|10}}|10}}|}}}} And this for 139 repeatings: {#ifexpr:({{{2|2}}}<=10)=1|{{Multi/1|{{{1}}}|{{{2|2}}}}}|{{Multi/1|{{{1}}}|{{#expr:{{{2|2}}}-({{#expr:floor({{{2|2}}}/10) round 0}}*10)}}}}<!-- -->{{Multi/1|{{Multi/1|{{{1}}}|10}}|{{#expr:floor({{{2|2}}}/10) round 0}}}}}} With the "Multi/1" being {{#replace:{{rmv|1|{{#expr:(10^{{{2|2}}})}}}}|0|{{{1}}}}} (the rmv template has {{#replace:{{{2}}}|{{{1}}}|}}) |
As you can see this is a shorter code than what is currently on the template(1355+57=1412 bytes instead of 5927 bytes) and it repeats almost 10 times as much. Joeytje50 (talk) 20:36, 21 November 2010 (UTC)
- Are you suggesting that we replace this template with your code? The nice thing about this code is that it has no expression nesting, which can be a major problem, given the 40 level limit for the Wikimedia servers. What is the post-expand size of your version? This is another issue for the servers. Also, is there a reason why we need to loop more than 149 times? Thanks! Plastikspork ―Œ(talk) 21:42, 21 November 2010 (UTC)
- So this code is not possible for wikipedia? Joeytje50 (talk) 20:39, 22 November 2010 (UTC)
- The issue is not so much if it would work most of the time, see Template:Repeat for example, but the complexity of what might be inside the loop. The nice thing about this implementation is that it has no nesting, which reducing the potential for nesting limits. I am just curious why we need to be looping so many times. Thanks! Plastikspork ―Œ(talk) 02:43, 23 November 2010 (UTC)
- It could be useful in any case. I don't know any, but if you scroll trough the template links, you will probably find examples of things that need repeating, so maybe you will be able to think of something yourself. And one question: what is "nesting"? is that the using of a template inside a template?Joeytje50 (talk) 19:18, 23 November 2010 (UTC)
- Yes, nesting is either using a template inside of another template (limit is 40 levels), or using a parser function inside of another parser function. For example, see the ongoing discussion at Template talk:convert or Template talk:documentation or Template talk:rnd. It is for this reason that we should try to keep these templates simple, and only add complexity when we need to. Thanks! Plastikspork ―Œ(talk) 06:26, 24 November 2010 (UTC)
- It could be useful in any case. I don't know any, but if you scroll trough the template links, you will probably find examples of things that need repeating, so maybe you will be able to think of something yourself. And one question: what is "nesting"? is that the using of a template inside a template?Joeytje50 (talk) 19:18, 23 November 2010 (UTC)
- The issue is not so much if it would work most of the time, see Template:Repeat for example, but the complexity of what might be inside the loop. The nice thing about this implementation is that it has no nesting, which reducing the potential for nesting limits. I am just curious why we need to be looping so many times. Thanks! Plastikspork ―Œ(talk) 02:43, 23 November 2010 (UTC)
- So this code is not possible for wikipedia? Joeytje50 (talk) 20:39, 22 November 2010 (UTC)
Loop and count
[edit]Is there anyway to use a Loop template or a module inside of a template that calls other templates and knows what the loop counter is? I want to {{#expr:{{Loop|{{PAGESINCAT:Articles with a promotional tone from {{Months before now|<!-- current loop number -->}}|pages}} + |{{PAGESINCAT:Articles with a promotional tone|subcats}}}}0}}
to give me a count of all of the subpages in that category. Can this be done? Technical 13 (talk)
Replace current template logic with a Scribunto module
[edit]Relevant discussion: https://wiki.riteme.site/w/index.php?title=Wikipedia:Lua_requests&oldid=557697440#Template:Loop --MZMcBride (talk) 15:31, 31 May 2013 (UTC)