This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing.
This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing.
-- This module implements {{for loop}}.localgetArgs=require('Module:Arguments').getArgslocalyesno=require('Module:Yesno')localp={}functionp.main(frame)localargs=getArgs(frame,{trim=false,removeBlanks=false})returnp._main(args)endfunctionp._main(args)localtemplate=args['call']or'void'localcalltemplates=yesno(args.substallor"",true)ornotmw.isSubsting()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=''localaddSeparator=false;for_,vinipairs(variableVals)dov=mw.text.trim(v)if#v>0ornotyesno(args.skipBlanks)thenifaddSeparatorthenresult=result..sependaddSeparator=true;localtargs=constantArgstargs[variableParam]=variableValPrefix..v..variableValPostfixifcalltemplatesthenlocaloutput=p.callTemplate(template,targs)if#mw.text.trim(output)==0thenaddSeparator=falseendresult=result..outputelselocalmakeTemplate=require('Module:Template invocation').invocationresult=result..makeTemplate(template,targs)endendendreturnresultendfunctionp.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={}ifargs.startorargs.stoporargs.bythenifargs[2]thenerror("Both start/stop/by and numbered parameters specified")endlocalstart=tonumber(args.startor1)localstop=tonumber(args.stopor1)localby=tonumber(args.byor1)fori=start,stop,bydovariableVals[#variableVals+1]=iendelsefori,vinipairs(args)doifi~=1thenvariableVals[i-1]=vendendendreturnvariableValsendfunctionp.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,_inpairs(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