پرش به محتوا
منوی اصلی
منوی اصلی
انتقال به نوار کناری
نهفتن
ناوبری
صفحهٔ اصلی
تغییرات اخیر
مقالهٔ تصادفی
راهنما دربارهٔ مدیاویکی
صفحههای ویژه
جستجو
جستجو
ظاهر
ساخت حساب
ورود
ابزارهای شخصی
ساخت حساب
ورود
صفحههایی برای ویرایشگرانی که از سامانه خارج شدند
بیشتر بدانید
مشارکتها
بحث
در حال ویرایش
الگو:For loop/توضیحات
الگو
بحث
فارسی
خواندن
ویرایش مبدأ
نمایش تاریخچه
ابزارها
ابزارها
انتقال به نوار کناری
نهفتن
کنشها
خواندن
ویرایش مبدأ
نمایش تاریخچه
عمومی
پیوندها به این صفحه
تغییرات مرتبط
اطلاعات صفحه
ظاهر
انتقال به نوار کناری
نهفتن
هشدار:
شما وارد نشدهاید. نشانی آیپی شما برای عموم قابل مشاهده خواهد بود اگر هر تغییری ایجاد کنید. اگر
وارد شوید
یا
یک حساب کاربری بسازید
، ویرایشهایتان به نام کاربریتان نسبت داده خواهد شد، همراه با مزایای دیگر.
بررسی ضدهرزنگاری. این قسمت را پر
نکنید
!
{{زیرصفحه توضیحات}} <!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE. --> {{لوآ|Module:ForLoop}} {{چپچین}} [[Template:For loop]] and [[Template:For loop/old]] implement a [[foreach loop]]. Template:For loop/old is a legacy template, and exists for reasons of backwards compatibility. If you need to use a for loop, it is almost always better to use Template:For loop, which is implemented as a [[ویکیپدیا:لوآ|Lua module]]. This template calls a user specified template once for each of a list of values. A named parameter is passed with the value from the list of the current iteration with a possible prefix and/or a postfix attached. In addition to the variable parameter, fixed parameters can be specified to be passed with each iteration. The first unnamed parameter is output between calls to the user specified template. == Usage == <pre> {{for loop|<!-- separator, whitespace is preserved -->| call = template to call | pc1n = name of the 1st static parameter passed to the called template | pc1v = value of the 1st static parameter passed to the called template | pc2n = name of the 2nd static parameter passed to the called template | pc2v = value of the 2nd static parameter passed to the called template | pc3n = name of the 3rd static parameter passed to the called template | pc3v = value of the 3rd static parameter passed to the called template <!-- More fixed parameters passed to the called template can be inserted as needed --> | pv = parameter name used to pass to the called template to which is assigned the variable values with prefix prepended and postfix apended. | prefix = static prefix prepended to each of the variable values | postfix = static postfix appended to each of the variable values | list of variable values with separator "|", whitespace is stripped (empty parameter values work in the regular way, they are ''not'' ignored like undefined ones) }} </pre> The separator is the first unnamed parameter, allowing it to start and/or end with [[Help:newlines and spaces|newlines and spaces]]. The separator is output ''between'' calls to the template named in <code>|call=</code>. It is not output after the last call to that template. The separator parameter is prior to the value list. If a value in the list contains an equals sign, use use {{الگوب|{{=}}}} (see [[راهنما:الگو|Help:Template]]). If you do not use {{الگوب|{{=}}}}, the list must use named parameters, at least from that point. If you use named parameters, note that the first value is parameter 2 (e.g. <code>|2=Your1stValue</code>), because parameter 1 is the separator. If the separator contains an equals sign, {{الگوب|{{=}}}} should also be used. Alternately, the separator can similarly be prefixed with "1=", but in that case it cannot contain newlines and spaces at the start and end. Also, if you use named parameters, you must not skip any numbers. The loop will terminate after the first absent numbered parameter. (Note that parameters can be blank but not absent; blank parameters are read as normal.) ==Examples== {| class="wikitable", border=1 !Code !Result |- | <pre>1{{for loop|, 1|00|01|02|03|04|05|06|07|08|09 |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|64|65|66|67|68|69 |70|71|72|73|74|75|76|77|78|79 |80|81|82|83|84|85|86|87|88|89 |90|91|92|93|94|95|96|97|98|99 |call=1x }}</pre> |1{{for loop|, 1|00|01|02|03|04|05|06|07|08|09 |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|64|65|66|67|68|69 |70|71|72|73|74|75|76|77|78|79 |80|81|82|83|84|85|86|87|88|89 |90|91|92|93|94|95|96|97|98|99 |call=1x }} |} Note that the last part of the separator is used as a prefix; the first prefix needs to be put separately. ---- <nowiki>{{for loop|-|a|3||c|g|call=3x}}</nowiki> using {{Tiw|3x}} gives {{for loop|-|a|3||c|g|call=3x}} <nowiki>{{for loop|</nowiki> <nowiki>|a|3||c|g|call=3x}}</nowiki> gives {{for loop| |a|3||c|g|call=3x}} <pre> {|class="wikitable sortable" |- !Test |- | {{for loop| {{!}}- {{!}} |a|b|c|d|e|call=3x}} |} </pre> gives: {|class="wikitable sortable" |- !Test |- | {{for loop| {{!}}- {{!}} |a|b|c|d|e|call=3x}} |} <pre> {{for loop| |01|02|03|04|05|06|07|08|09|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|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79 |80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99 |100|101|102|103|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119 |120|121|122|123|124|125|126|127|128|129|130|131|132|133|134|135|136|137|138|139 |140|141|142|143|144|145|146|147|148|149|150|151|152|153|154|call=1x}} </pre> gives: {{for loop| |01|02|03|04|05|06|07|08|09|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|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79 |80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99 |100|101|102|103|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119 |120|121|122|123|124|125|126|127|128|129|130|131|132|133|134|135|136|137|138|139 |140|141|142|143|144|145|146|147|148|149|150|151|152|153|154|call=1x}} <pre> begin->{{for loop|{{=}} |01|02|03|04|05|06|07|08|09|10 |11{{=}}{{=}}{{=}}|12|13|14|15|16|17|18|19|call=1x}}<-end </pre> gives: begin->{{for loop|{{=}} |01|02|03|04|05|06|07|08|09|10 |11{{=}}{{=}}{{=}}|12|13|14|15|16|17|18|19|call=1x}}<-end == Legacy code == This template is currently in its third incarnation. It is now uses the [[ویکیپدیا:لوآ|Lua]] code at [[پودمان:ForLoop]]. It was ported to Lua from [[mw:Help:Extension:ParserFunctions|ParserFunctions]], and the old code is available at {{الگو|for loop/old}}. There was also a previous version with a named "sep" parameter to specify the separator value. The template was originally based on [[:m:Template:For]]. The template name was changed because there was already a [[الگو:برای]] on Wikipedia. The old versions were limited to 150 variable values and four fixed parameters. There are no such limits in the current version. Also, in the first version the "sep" parameter didn't allow whitespace in the separator value. This was fixed with the second version and was retained in the current version. === Substitution === The current Lua-based template supports [[ویکیپدیا:جانشینی|substitution]] of the whole template call. To substitute everything, use {{الگوج|for loop}}. The previous ParserFunctions-based template supported varying levels of substitution. If you wish to have fine-grained control over substitution, you need to use {{الگو|for loop/old}}. For successive levels of substitution use one or more or the following (the first, the first two, the first three, the first four, or all five). *"subst:" in front of "for loop/old" - substitute the call of {{الگو|for loop/old}} *substf=subst: - substitute the parser functions in {{الگو|for loop/old}} *substfa=subst: - substitute the call of {{الگو|ForLoop/aux}}, a helper subtemplate *substa=subst: - substitute the parser functions in {{الگو|ForLoop/aux}} (reduces the number of items from 150 to the actual number) *substc=subst: - substitute the calls of the user template If at least the first four are applied, and the separator contains <code><nowiki>{{!}}</nowiki></code>, one can replace it with <code><nowiki>{{subst:!}}</nowiki></code> to substitute that too. For full substitution [[Special:ExpandTemplates]] can also be used. === Converting legacy template invocations === If you need to convert a template invocation that was written for the original version of {{الگو|for loop}}, do the following: *replace <code>pc1=X=Y</code> with <code>pc1n=X | pc1v=Y</code>, etc. *use an unnamed parameter for the separator; if empty, just enter an extra "|" No conversion is necessary for invocations written for the second version of the template, unless they use fine-grained substitution as mentioned in the section above. If you need fine-grained substitution you should use {{الگو|for loop/old}} instead of {{الگو|for loop}}. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 09:44, 19 July 2013 (UTC) ==See also== *[[mw:Template:Fe]] *{{Tim|foreach}} *{{Tim|tblb}} *{{Tiw|loop}} *{{Tiw|repeat}} *{{Tiw|simple recursion}} *[[Help:Parameter default]] *[[Help:Array]] *[[mw:Extension:LoopFunctions]] {{پایان چپچین}} <includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox|| <!-- CATEGORIES AND INTERWIKIS HERE, THANKS --> [[رده:الگو:قالببندی و عملکرد ویکیپدیا|{{PAGENAME}}]] }}</includeonly>
خلاصه:
لطفاً توجه داشته باشید که همهٔ مشارکتها در ایرانپدیا ممکن است توسط دیگر مشارکتکنندگان تغییر یابند، ویرایش یا حذف شوند. اگر نمیخواهید نوشتههایتان بیرحمانه ویرایش شوند؛ بنابراین، آنها را اینجا ارائه نکنید.
شما همچنین به ما تعهد میکنید که خودتان این را نوشتهاید یا آن را از یک منبع با مالکیت عمومی یا مشابه آزاد آن برداشتهاید (
ایرانپدیا:حق تکثیر
را برای جزئیات بیشتر ببینید).
کارهای دارای حق تکثیر را بدون اجازه ارائه نکنید!
لغو
راهنمای ویرایش
(در پنجرهٔ تازه باز میشود)
پیشنمایش صفحه با این الگو
الگوهای بهکاررفته در این صفحه:
الگو:1x
(
ویرایش
)
الگو:3x
(
ویرایش
)
الگو:For loop
(
ویرایش
)
الگو:Mbox
(
ویرایش
)
الگو:Namespace detect
(
ویرایش
)
الگو:Ombox/styles.css
(
ویرایش
)
الگو:Tim
(
ویرایش
)
الگو:Tiw
(
ویرایش
)
الگو:آغاز چپچین
(
ویرایش
)
الگو:الگو
(
ویرایش
)
الگو:الگوب
(
ویرایش
)
الگو:الگوج
(
ویرایش
)
الگو:زیرصفحه توضیحات
(
ویرایش
)
الگو:لوآ
(
ویرایش
)
الگو:پایان
(
ویرایش
)
الگو:پایان چپچین
(
ویرایش
)
الگو:چپچین
(
ویرایش
)
پودمان:Arguments
(
ویرایش
)
پودمان:ForLoop
(
ویرایش
)
پودمان:List
(
ویرایش
)
پودمان:Lua banner
(
ویرایش
)
پودمان:Message box
(
ویرایش
)
پودمان:Message box/configuration
(
ویرایش
)
پودمان:Message box/ombox.css
(
ویرایش
)
پودمان:Namespace detect
(
ویرایش
)
پودمان:Namespace detect/config
(
ویرایش
)
پودمان:Namespace detect/data
(
ویرایش
)
پودمان:TableTools
(
ویرایش
)
پودمان:Template invocation
(
ویرایش
)
پودمان:Yesno
(
ویرایش
)
جستجو
جستجو
در حال ویرایش
الگو:For loop/توضیحات
افزودن مبحث