Sign in to follow this  
Followers 0
rediff

NO GoTo Function??

14 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

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 ...
 

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 ;pointB

Next

some statement

Exit Loop

Now, 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

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 by rediff

Share this post


Link to post
Share on other sites

Hi MvGulik,

can u please elaborate on what is GoTO AutoIT manual/documentation

GoTO AutoIt manual/documentation should do the trick.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

~

Edited by Mobius

Share this post


Link to post
Share on other sites

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 game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

#8 ·  Posted (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.

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

Edited by rediff

Share this post


Link to post
Share on other sites

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 ...
 

Share this post


Link to post
Share on other sites

If my understanding is correct, you want a ContinueLoop command.

Share this post


Link to post
Share on other sites

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.

If my understanding is correct, you want a ContinueLoop command.

Share this post


Link to post
Share on other sites

ContinueLoop would be used at the point you wanted to "goto" the beginning of the next loop iteration.

Share this post


Link to post
Share on other sites

#13 ·  Posted (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.

:graduated:

Edit: Got rid of the Send(), which only confuses the issue.

Edited 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

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0