Loop - Syntax & Usage - AutoHotkey
文章推薦指數: 80 %
The Loop statement performs a series of code lines repeatedly: either the specified number of times or until a Break statement is encountered. Loop(normal) Performsaseriesofcommandsrepeatedly:eitherthespecifiednumberoftimesoruntilbreakisencountered. Loop,Count Parameters Count Howmanytimes(iterations)toperformtheloop.Ifomitted,theLoopcontinuesindefinitelyuntilabreakorreturnisencountered. IfCountisavariablereferencesuchas%ItemCount%,theloopisskippedentirelywheneverthevariableisblankorcontainsanumberlessthan1. Duetotheneedtosupportfile-patternloops,Countcannotbeanexpression.However,aswithallnon-expressionparameters,anexpressioncanbeforciblyusedbyprecedingitwitha%andaspace.Forexample:Loop%Count+1.Insuchcases,theexpressionisevaluatedonlyonce,rightbeforetheloopbegins. Remarks Theloopcommandisusuallyfollowedbyablock,whichisacollectionofstatementsthatformthebodyoftheloop.However,aloopwithonlyasinglestatementdoesnotrequireablock(an"if"andits"else"countasasinglestatementforthispurpose). Acommonuseofthiscommandisaninfiniteloopthatusesthebreakcommandsomewhereintheloop'sbodytodeterminewhentostoptheloop. Theuseofbreakandcontinueinsidealoopareencouragedasalternativestogoto,sincetheygenerallymakeascriptmoreunderstandableandmaintainable.Onecanalsocreatea"While"or"Do...While/Until"loopbymakingthefirstorlaststatementoftheloop'sbodyanIFstatementthatconditionallyissuesthebreakcommand,buttheuseofWhileorLoop...Untilisusuallypreferred. Thebuilt-invariableA_Indexcontainsthenumberofthecurrentloopiteration.Itcontains1thefirsttimetheloop'sbodyisexecuted.Forthesecondtime,itcontains2;andsoon.Ifaninnerloopisenclosedbyanouterloop,theinnerlooptakesprecedence.A_Indexworksinsidealltypesofloops,includingfile-loopsandregistry-loops;butA_Indexcontains0outsideofaloop. TheOneTrueBrace(OTB)stylemayoptionallybeusedwithnormalloops(butnotspecializedloopssuchasfile-patternandparsing).Forexample: Loop{ ... } Loop%RepeatCount%{ ... } Specializedloops:Loopscanbeusedtoautomaticallyretrievefiles,folders,orregistryitems(oneatatime).Seefile-loopandregistry-loopfordetails.Inaddition,file-readingloopscanoperateontheentirecontentsofafile,onelineatatime.Finally,parsingloopscanoperateontheindividualfieldscontainedinsideadelimitedstring. Related Until,While-loop,For-loop,Files-and-foldersloop,Registryloop,File-readingloop,Parsingloop,Break,Continue,Blocks Examples Createsaloopwith3iterations. Loop,3 { MsgBox,Iterationnumberis%A_Index%.;A_Indexwillbe1,2,then3 Sleep,100 } Createsaninfiniteloop,butitwillbeterminatedafterthe25thiteration. Loop { if(A_Index>25) break;Terminatetheloop if(A_Index<20) continue;Skipthebelowandstartanewiteration MsgBox,A_Index=%A_Index%;Thiswilldisplayonlythenumbers20through25 }
延伸文章資訊
- 1Loop until hotkey released : r/AutoHotkey - Reddit
I want my script to continue looping until I've released the hotkey which triggered it. Any sugge...
- 2AHK turn off loop when Key is pressed - Stack Overflow
I created a code that should send the "E" key until i press the "T" key. Right now the loop only ...
- 3Until - Syntax & Usage - AutoHotkey
The Until statement applies a condition to the continuation of a Loop or For-loop.
- 4loop until i press a key - Ask for Help - AutoHotkey Community
i really have a problem with this... here's a example: loop { Send, text1{enter} Send, text2 Esc:...
- 5Loop - Syntax & Usage - AutoHotkey
The Loop statement performs a series of code lines repeatedly: either the specified number of tim...