rediff Posted November 10, 2010 Posted November 10, 2010 Hi, I am new to Auto It, but from what I have understood so far there is no GoTo function available. Is that correct ? If yes, then I am stuck at the following point I am running a for loop, where exceptions can arise, so code of body looks like the followiing:- For $i = 1 to 100 Send("{DOWN " & $i & "}") ; point A and other statements IF(execption) execute some other statements EndIf Next some statement Exit Loop Now my problem is that I need that once an exception arises and it has executed the statements in the if block, it should go back to point A with an updated value of $i. Basically corresponding to each value of $i , I need to check if there is an exception. I was thinking that if goto statement was available, I would have increased the index of $i by 1 in the if block($i = $i+1) and then used the goto statement to jump to statement at point A. But, now I do not know, how can I go about this. Kindly help. Thanks
kaotkbliss Posted November 10, 2010 Posted November 10, 2010 (edited) You don't need a goto function While loop do stuff if condition _Myfunc() <-- function call endif wend <-- end loop Func _Myfunc() some stuff to do endfunc at the function call it will enter the function, perform its actions, then return to where it left off. Edited November 10, 2010 by kaotkbliss 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy!
MvGulik Posted November 10, 2010 Posted November 10, 2010 GoTO AutoIt manual/documentation should do the trick. "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ...
rediff Posted November 10, 2010 Author Posted November 10, 2010 (edited) Hi kaotkbliss, Thanks for the quick reply. I forgot to mention a part of my code. Sorry about this. For $i = 1 to 100 Send("{DOWN " & $i & "}") ; point A and other statements IF(execption) execute some other statements EndIf some more statements ;pointBNextsome statementExit LoopNow, the problem is,If an exception is encountered, I don't want to execute the statements after the IF block(i.e point B statements). I want it to go execute the statements at point A(after the IF block). And also, I cannot move the IF block at the end, because the exception can arise only after point A statements.So now if I use the while loop and make a separate function to handle the exception, it would still execute the statements at point B ( after returning from the function) which I don't want. Kindly advise On 11/10/2010 at 8:27 PM, 'kaotkbliss said: You don't need a goto functionWhile loopdo stuffif condition_Myfunc() <-- function callendifwend <-- end loopFunc _Myfunc()some stuff to doendfuncat the function call it will enter the function, perform its actions, then return to where it left off. Edited November 10, 2010 by rediff
rediff Posted November 10, 2010 Author Posted November 10, 2010 Hi MvGulik, can u please elaborate on what is GoTO AutoIT manual/documentation On 11/10/2010 at 8:31 PM, 'MvGulik said: GoTO AutoIt manual/documentation should do the trick.
kaotkbliss Posted November 10, 2010 Posted November 10, 2010 Then you would what to do something like While loop do suff if condition _myfunc() else _otherfunc() endif wend Func _myfunc() do stuff endfunc Func _otherfunc() do other stuff endfunc what will happen is each time it runs through the loop and checks the condition if yes, then perform _myfunc if not perform _otherfunc if, after condition is yes you don't want to continue checking then add ExitLoop on the line after the _Myfunc call 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy!
rediff Posted November 10, 2010 Author Posted November 10, 2010 (edited) Hi kaotkbliss, Thanks for your help I will try this.But from what I understand, if at the end of IF block I will add the statement EXIT Loop, would it not altogether exit(stop) the loop ? I do not want that. I need that after the IF block, the loop should continue testing for the next field. And so after the IF Block it should execute statements from the start again for the next field. That is if for $i = 10, it enters the IF block. For $i = 11, it should start executing statements at point A. On 11/10/2010 at 9:05 PM, 'kaotkbliss said: Then you would what to do something likeWhile loopdo suffif condition_myfunc()else_otherfunc()endifwendFunc _myfunc()do stuffendfuncFunc _otherfunc()do other stuffendfuncwhat will happen is each time it runs through the loop and checks the conditionif yes, then perform _myfunc if not perform _otherfuncif, after condition is yes you don't want to continue checking then add ExitLoop on the line after the _Myfunc call Edited November 10, 2010 by rediff
MvGulik Posted November 10, 2010 Posted November 10, 2010 On 11/10/2010 at 8:57 PM, 'rediff said: Hi MvGulik, can u please elaborate on what is GoTO AutoIT manual/documentation Sure. "GoTO AutoIT manual/documentation" Is is a small combination of letters, that form words, witch form a small virtual communication packet. On the content of that communication packet I was probably a little premature. Although kaotkbliss seems to be working on fixing that. While loop ;; do suff If condition Or exception Then _myfunc() Else _otherfunc() EndIf WEnd Func _myfunc() ;; do stuff EndFunc Func _otherfunc() ;; do other stuff EndFunc "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ...
Richard Robertson Posted November 11, 2010 Posted November 11, 2010 If my understanding is correct, you want a ContinueLoop command.
rediff Posted November 12, 2010 Author Posted November 12, 2010 where can I use a continue loop command ? instead of Exit Loop at the end of the IF Block ? Wont, then the code execute the statements at point B ? I need it to execute point A statements, without exiting the loop, in case for a certain value of $i, it enters the IF Block. Thanks. On 11/11/2010 at 6:30 PM, 'Richard Robertson said: If my understanding is correct, you want a ContinueLoop command.
Richard Robertson Posted November 12, 2010 Posted November 12, 2010 ContinueLoop would be used at the point you wanted to "goto" the beginning of the next loop iteration.
PsaltyDS Posted November 12, 2010 Posted November 12, 2010 (edited) This is worth learning, but is not going to make sense until you start working in real code instead of pseudo-code full of unspoken assumptions. Let's start from here. This is a corrected runnable demo of your post #4 code: For $i = 1 To 100 ConsoleWrite("Testing: " & $i & @LF) ; point A ;and other statements If Mod($i, 4) = 0 Then ; If divisible by 4 _Exception($i) ContinueLoop ; continues at start of loop, without running the rest of the current pass EndIf ConsoleWrite("$i = " & $i & "; Not divisible by 4" & @LF) ; pointB Next ConsoleWrite("Loop is done..." & @LF) Func _Exception($iVal) ConsoleWrite($iVal & " is divisible by 4!" & @LF) EndFunc ;==>_Exception Run this and see how it works. Make it a rule for the rest of this topic not speculate on what might happen without actually changing that code and running it, then posting your version if you have more questions. Edit: Got rid of the Send(), which only confuses the issue. Edited November 12, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Arion Posted November 14, 2010 Posted November 14, 2010 Next time you get stuck, think about context. If you're working in a loop, look at the loops in the help file, most of the time you will either find what you were looking for, or find a better way. [quote]“Programming is like *ex: one mistake and you’re providing support for a lifetime.”(Michael Sinz)[/quote] [quote]“There are two ways to write error-free programs; only the third one works.”(Alan J. Perlis)[/quote]
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now