Jump to content

Template talk:Loop

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
(Redirected from Template talk:Loop/doc)

Question

[edit]

What is the difference between this template and {{Loop1}}?—Ëzhiki (Igels Hérissonovich Ïzhakoff-Amursky) • (yo?); 16:03, 23 March 2007 (UTC)[reply]

QUESTION

[edit]

Where do you type it in? —Preceding unsigned comment added by 76.126.233.15 (talk) 03:18, 1 May 2008 (UTC)[reply]

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)[reply]

Yes, it does.--Patrick (talk) 13:52, 28 January 2008 (UTC)[reply]

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)[reply]

Yes, the *2 does not seem needed.--Patrick (talk) 08:33, 1 May 2008 (UTC)[reply]

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)[reply]

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)[reply]

Edit request

[edit]

Please update {{/doc}} with {{documentation}}. Per Wikipedia:Template documentation/List Thankyou. -- αŁʰƏЩ @ 06:13, 28 April 2008 (UTC)[reply]

Done.--Patrick (talk) 07:23, 28 April 2008 (UTC)[reply]

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)[reply]

That should work, can you give a link to your attempt?--Patrick (talk) 07:40, 11 September 2009 (UTC)[reply]

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.

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)[reply]

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)[reply]
So this code is not possible for wikipedia? Joeytje50 (talk) 20:39, 22 November 2010 (UTC)[reply]
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)[reply]
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)[reply]
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)[reply]

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://en.wikipedia.org/w/index.php?title=Wikipedia:Lua_requests&oldid=557697440#Template:Loop --MZMcBride (talk) 15:31, 31 May 2013 (UTC)[reply]