Simple Until Loop - AutoHotkey Community

文章推薦指數: 80 %
投票人數:10人

Loop Until not triggering - AutoHotkey Community AutoHotkeyCommunity Let'shelpeachotherout Skiptocontent Home Quicklinks Unansweredtopics Activetopics Search WebSearch Forums Members Theteam IRC Commands Tutorial Download - 1.1.34.04 FAQ Login Register Search Login Register WebSearch Search Advancedsearch Home Boardindex AutoHotkey AskForHelp Search Itiscurrently25Aug2022,14:38 AlltimesareUTC-05:00 SimpleUntilLoop Topicissolved GethelpwithusingAutoHotkeyanditscommandsandhotkeys Forumrules PostReply Emailtopic Printview Search Advancedsearch 36posts 1 2 Next Barney15 Posts:162 Joined:12Jan2020,14:18 SimpleUntilLoop Reportthispost @ Quote 05May2020,08:28 >method1 *Until Code:Selectallx=0 Loop { x++ if(x=10) { x-=10 y+=1 } ToolTip,%"Counting".x."`nRepeat".y } Untily=100 >method2 *While Code:Selectallx=0 y=1 Whiley<100 { x++ if(x>10) { x-=10 y+=1 } ToolTip,%"Counting".x."`nRepeat".y Sleep,400 } ifyoucanthinkofothermethodsplease,becausei'msearchingformoreprofessionalwrittentothiscode. isusingforpossible. Top Smile_ Posts:690 Joined:03May2020,00:51 Re:SimpleUntilLoop Reportthispost @ Quote 05May2020,09:53 Wahtaboutthis: Code:Selectallx=0 y=1 Count: ToolTip,%"Counting".x."`nRepeat".y x+=1 ifx=10 { y+=1 x=0 } ify<>100 Goto,Count else Return Top boiler Posts:12258 Joined:21Dec2014,02:44 Re:SimpleUntilLoop Reportthispost @ Quote 05May2020,10:01 Barney15wrote:↑05May2020,08:28 isusingforpossible. Forisonlyusedwithobjects,andtheredoesn’tlooktobeagoodreasontocreateanobjectforthispurpose.Youalreadyhavechosenthetwobestchoicesinwhileanduntil.Irecommendavoidinggotoasitpromotesbadprogrammingpractices. Top Barney15 Posts:162 Joined:12Jan2020,14:18 Re:SimpleUntilLoop Reportthispost @ Quote 05May2020,10:43 Iunderstand,butcantheloopbecreatedinawaysimilarto #include usingnamespacestd; intmain(){ for(intx=1;x<=10;x++){ cout<100/Goto,Count.Onereasonisthatvisually,aloopandthebracesdefiningthecodeblockallowyoutoseetheflowofcontroleasily.Anotheristhatloop/untilorwhileareconcisestatementsofthelogicthatistobefollowed. Ingeneral,usinggotopromotesbadprogrammingpracticesbecauseitdoesn'tsupportstructuredprogramflow.Let'scomparegototogosub.Withgosub,youcancallthesamelabelfrommanydifferentpartsofthescript,andwithasimplereturn,theexecutionwillpickupfromwhereitwascalled.Withgoto,youdon'tknowhowitgotthereandwheretogotonext,makingitmuchlessflexible.Itlimitstheabilitytohaveflexibleandre-usablecode.Nothavinggoodstructuremakescriptsunwieldyandleadstowhatisknownas"spaghetticode."(Bytheway,afunctioncallisusuallyevenbetterthangosubbecauseitmaintainsscopeofvariables,canhaveparameterspassedtoit,canreturnvalues,andhastheaboveadvantagesofasubroutinecalledbygosub,amongothers.) AmIsayingtoneverusegoto?No,althoughIrarelyifeverfindareasontouseit.Canyouusegotocarefullytoavoidsuchissues?Possibly,buttherearealmostalwaysbetteroptionsbecauseittakesmoreworkontheprogrammer'spartandmakescodehardertomaintain.I'vestatedseveralreasonswhyothermethodsarebetter.Arethereanyreasonsyoucanstatewhygotoissuperiortotheothermethods?Itispossibletogetthejobdoneusingit,butitlackstheadvantagesoftheothermethods,soit'sbesttogetintothehabitofusingthem. Top Barney15 Posts:162 Joined:12Jan2020,14:18 Re:SimpleUntilLoop Reportthispost @ Quote 05May2020,14:01 @swagfagi'vepostedthatmethod>method2 @boiler IuseGotosometimes,it'sfacilitatethetask,andiseeanydifferentmethodthanusingGoto,isbetterwaytocodeandmoreofprogrammingstructure. willyoupleaseprovidemewithanexamplethaticouldexecutetofindthedifferentbetweenGotoandGosub. ididreadonlinesomearticlesbutneverfoundsimpleexcitableexample. Top Smile_ Posts:690 Joined:03May2020,00:51 Re:SimpleUntilLoop Reportthispost @ Quote 05May2020,14:04 @boiler ItisOKyoudon'tneedtowriteallofthistoexplainyourpoint.Justdidntpaymuchattentiontothisspecificationmoreprofessional. Top Barney15 Posts:162 Joined:12Jan2020,14:18 Re:SimpleUntilLoop Reportthispost @ Quote 05May2020,14:06 andigotthisnewhabit, insteadofusingvariables,xy.... iuseonesinglearrayandtakevariablefromit,eg:AHK:=[0,1]useAHK[1]&AHK[2] thatwayicanavoidrepetitionandwritinglesslines,pulseitlookmorepersonalized. Top boiler Posts:12258 Joined:21Dec2014,02:44 Re:SimpleUntilLoop Reportthispost @ Quote 05May2020,14:16 Smile_wrote:↑ ItisOKyoudon'tneedtowriteallofthistoexplainyourpoint.Justdidntpaymuchattentiontothisspecificationmoreprofessional. Iassumedfromyourquestion"Whybadpractise?"thatyouactuallywantedtoknowwhy. Top boiler Posts:12258 Joined:21Dec2014,02:44 Re:SimpleUntilLoop Reportthispost @ Quote 05May2020,14:43 Barney15wrote:↑05May2020,14:01 willyoupleaseprovidemewithanexamplethaticouldexecutetofindthedifferentbetweenGotoandGosub. ididreadonlinesomearticlesbutneverfoundsimpleexcitableexample. Hereisacontrivedexampleofwhyyouwouldneveruseagotoinasituationlikethis.It'snotforyoutoexecute,butjusttoinspect.Youwouldseeonlyseethedifferencefromlookingatthecode,notexecutingitanyway.Iftheyranthem,youwouldn'tseetheadvantage.Theadvantageisinthewriting,debugging,andmaintainingofthecode.NoticealltheworkyouhavetoputintoknowingwheretogonextifyoutrytoresusetheAnswerConfirmsubroutine. Gosubversion: Code:SelectallWinWaitActive,Question Send,457{Enter} gosub,AnswerConfirm WinWaitActive,Question Send,1005{Enter} gosub,AnswerConfirm WinWaitActive,Question Send,0 gosub,AnswerConfirm return AnswerPopup: WinWaitActive,Isthisvaluecorrect? ImageSearch,yesX,yesY,0,0,A_ScreenWidth,A_ScreenHeight,yesimage.png ifErrorLevel MsgBox,Couldnotclosepopup else Click,%yesX%,%yesY% return Gotoversion: Code:SelectallQuestion:=1 WinWaitActive,Question Send,457{Enter} goto,AnswerConfirm Question2: Question:=2 WinWaitActive,Question Send,1005{Enter} goto,AnswerConfirm Question3: Question:=3 WinWaitActive,Question Send,0 goto,AnswerConfirm return AnswerPopup: WinWaitActive,Isthisvaluecorrect? ImageSearch,yesX,yesY,0,0,A_ScreenWidth,A_ScreenHeight,yesimage.png ifErrorLevel MsgBox,Couldnotclosepopup else Click,%yesX%,%yesY% if(Question=1) gotoQuestion2 elseif(Question=2) gotoQuestion3 else ExitApp return Top Smile_ Posts:690 Joined:03May2020,00:51 Re:SimpleUntilLoop Reportthispost @ Quote 05May2020,15:41 Iassumedfromyourquestion"Whybadpractise?"thatyouactuallywantedtoknowwhy. @boiler WellandIassumed1or2linesexplanationnotwholebookpage. LasteditedbySmile_on05May2020,16:32,edited2timesintotal. Top boiler Posts:12258 Joined:21Dec2014,02:44 Re:SimpleUntilLoop Reportthispost @ Quote 05May2020,16:00 OK.I'llknowbetternottoansweryouinthefuture. Top Smile_ Posts:690 Joined:03May2020,00:51 Re:SimpleUntilLoop Reportthispost @ Quote 05May2020,16:35 @boilerImeannooffense,Ijustdon'twanttodisturbyou,ImeanImighttakemuchfromyourtimebywritingallofthis. Thanksforyouralleffortsnow,inthepast,inthefuturifwelived.MyapologizeforeverythingIsaidtoyouthatannoyedyou,hopeyouacceptit. Top boiler Posts:12258 Joined:21Dec2014,02:44 Re:SimpleUntilLoop Reportthispost @ Quote 05May2020,16:39 OK.Noproblem.Ijustwantedtoprovideathoroughandhelpfulanswer. Top Smile_ Posts:690 Joined:03May2020,00:51 Re:SimpleUntilLoop Reportthispost @ Quote 05May2020,16:44 @boiler Thankssomuch,I'mreallysohappythatyouforgivenme.IllbemorecarefulwithwhatIwriteinthenextdays. Top Smile_ Posts:690 Joined:03May2020,00:51 Re:SimpleUntilLoop Reportthispost @ Quote 05May2020,20:34 @boiler @Barney15 boilerwrote:↑05May2020,11:11 Yeah,there'snotreallytheequivalenttothatinAHK.Inyourexample,Iactuallywouldjustusenestedloopstatementsforxandyratherthanincrementingthemandresettingxyourself.Thefollowingloopstheinnerloop10timesforeverypassthroughtheouterloop: Code:SelectallLoop,100{ y:=A_Index;becauseitwillbeusedintheinnerloopsocan'trefertobothasA_Index loop,10{;A_Indexisx ToolTip,%"Counting".A_Index."`nRepeat".y Sleep,25 } } Tome,that'smuchcleanerthanincrementingandmonitoringyourownindexnumbers. Youcanusejustoneloop Code:SelectallLoop,1000{ ToolTip,%"Counting".Mod(A_Index,10)."`nRepeat".A_Index//10;x=Mod(A_Index,10)andy=A_Index//10 } Top Displaypostsfromprevious:Allposts1day7days2weeks1month3months6months1year SortbyAuthorPosttimeSubjectAscendingDescending PostReply Emailtopic Printview 36posts 1 2 Next Returnto“AskForHelp” Jumpto AutoHotkeyFoundation   AboutThisCommunity   ForumIssues AutoHotkey   AskForHelp     Gaming     AutoHotkeyv2Help   ScriptsandFunctions     Gaming     AutoHotkeyv2ScriptsandFunctions   Tutorials     TipsandTricks     TipsandTricksforv2   WishList     Suggestionsondocumentationimprovements   BugReports   AutoHotkeyv2Development   AutoHotkey_H     AskForHelp     Development   Announcements   Editors     AdventureIDE       OldTopics     AHKStudio     Notepad++     PuloversMacroCreator     SciTE4AutoHotkey     VisualStudioCode   GeneralDiscussion General   OtherUtilities&Resources   OtherProgrammingLanguages     C/C++     ASM     C#   Offtopic   RPA Otherlanguages   LookingforVolunteersinotherlanguages   Deutsch(German)     IchbraucheHilfe       Spiele     SkripteundFunktionen     Tutorials     Tooltime     Allgemeines   中文(Chinese)     请求帮助     脚本函数     教程资料     相关工具     其他   Español(Spanish)     PedirAyuda       AutomatizacióndeJuegos     ScriptsyFunciones     Tutoriales     OtrasUtilidadesyRecursos     General   Русский(Russian)     Помощь       СкриптыдляИгр     Скриптыибиблиотеки     Статьиируководства     ПрочиересурсыиПО.     Свободноеобщение   Français(French)     J'aibesoind'aide     ScriptsetFonctions     Tutoriels     AutresUtilitairesetRessources     HorsSujet   Português(Portuguese)     AjudaeSuporteGeral     ScriptseFunções     Tutoriais     OutrasFerramentaseRecursos     OutrosAssuntos   한국어(Korean) Whoisonline Usersbrowsingthisforum:Bing[Bot],dellarocco88,holotaro,pto,wddogger,Yasinand67guests Home Boardindex AlltimesareUTC-05:00 Deletecookies Theteam Contactus PoweredbyphpBB®ForumSoftware©phpBBLimited StylebyArty    



請為這篇文章評分?