This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected.
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is semi-protected from editing.
This module implements {{for loop}}. Please see the template page for documentation.
-- This module implements {{for loop}}.localgetArgs=require('Module:Arguments').getArgsp={}functionp.main(frame)localargs=getArgs(frame,{trim=false,removeBlanks=false})returnp._main(args)endfunctionp._main(args)localtemplate=args['call']or'void'localvariableParam=args.pvvariableParam=tonumber(variableParam)orvariableParamor1-- fix for positional parameterslocalvariableValPrefix=args.prefixor''localvariableValPostfix=args.postfixor''localsep=args[1]or''localconstantArgs=p.getConstants(args)localvariableVals=p.getVariableVals(args)localresult=''fori,vinipairs(variableVals)dov=mw.text.trim(v)-- trim whitespacelocaltargs=constantArgstargs[variableParam]=variableValPrefix..v..variableValPostfixlocalexpandedTemplate=p.callTemplate(template,targs)result=result..expandedTemplateifvariableVals[i+1]thenresult=result..sependendreturnresultendfunctionp.getConstants(args)localconstantArgNums=p.getArgNums(args,'pc','n')localconstantArgs={}for_,numinipairs(constantArgNums)dolocalkeyArg='pc'..tostring(num)..'n'localvalArg='pc'..tostring(num)..'v'localkey=args[keyArg]key=tonumber(key)orkeylocalvalue=args[valArg]constantArgs[key]=valueendreturnconstantArgsendfunctionp.getVariableVals(args)localvariableVals={}fori,vinipairs(args)doifi~=1thenvariableVals[i-1]=vendendreturnvariableValsendfunctionp.getArgNums(args,prefix,suffix)-- Returns a table containing the numbers of the arguments that exist-- for the specified prefix and suffix.localnums={}localpattern='^'..prefix..'([1-9]%d*)'..suffix..'$'fork,vinpairs(args)dolocalnum=tostring(k):match(pattern)ifnumthennums[#nums+1]=tonumber(num)endendtable.sort(nums)returnnumsendfunctionp.callTemplate(template,targs)returnmw.getCurrentFrame():expandTemplate{title=template,args=targs}endreturnp