Sign in to follow this  
Followers 0
faldo

Question about loops

5 posts in this topic

I remember a few versions back, i used to get a whole lot of "recursion error" (or something like that) in Do...Until-loops when i had the script running for a few days in a row accessing the loop. I solved the problem by useing While...wend-loops instead but i have one question that still haunts me.

If i have the following loop:

Dim $count=1
Do
    $count=$count+1
    If $count=10 Then
        $count=1
        MsgBox(0, "", "Count is 10")
        NextFunction()
    EndIf
Until @error

Func NextFunction()
;~  blablabla
EndFunc

...will it terminate the loop when i "goto" the next function or will the loop continue in the background? Do i need to use Exitloop just in case, like this:

Dim $count=1
Do
    $count=$count+1
    If $count=10 Then
        $count=1
        MsgBox(0, "", "Count is 10")
        NextFunction()
        Exitloop
    EndIf
Until @error

Func NextFunction()
;~  blablabla
EndFunc

Share this post


Link to post
Share on other sites



I remember a few versions back, i used to get a whole lot of "recursion error" (or something like that) in Do...Until-loops when i had the script running for a few days in a row accessing the loop. I solved the problem by useing While...wend-loops instead but i have one question that still haunts me.

If i have the following loop:

Dim $count=1
Do
    $count=$count+1
    If $count=10 Then
        $count=1
        MsgBox(0, "", "Count is 10")
        NextFunction()
    EndIf
Until @error

Func NextFunction()
;~  blablabla
EndFunc

...will it terminate the loop when i "goto" the next function or will the loop continue in the background? Do i need to use Exitloop just in case, like this:

Dim $count=1
Do
    $count=$count+1
    If $count=10 Then
        $count=1
        MsgBox(0, "", "Count is 10")
        NextFunction()
        Exitloop
    EndIf
Until @error

Func NextFunction()
;~  blablabla
EndFunc
Dim $count=1
Do
    $count=$count+1
    If $count=10 Then
        $count=1
        MsgBox(0, "", "Count is 10")
        NextFunction()
        Msgbox(0,'','Yes it continues but goes to Nextfunctionfirst() ^^ ')
        Exitloop
    EndIf
Until @error

Func NextFunction()
Msgbox(0,'','Some text here')
EndFunc

Try running this, i think you'll have your answer :P

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I remember a few versions back, i used to get a whole lot of "recursion error" (or something like that) in Do...Until-loops when i had the script running for a few days in a row accessing the loop. I solved the problem by useing While...wend-loops instead but i have one question that still haunts me.

If i have the following loop:

Dim $count=1
Do
    $count=$count+1
    If $count=10 Then
        $count=1
        MsgBox(0, "", "Count is 10")
        NextFunction()
    EndIf
Until @error

Func NextFunction()
;~  blablabla
EndFunc

...will it terminate the loop when i "goto" the next function or will the loop continue in the background? Do i need to use Exitloop just in case, like this:

Dim $count=1
Do
    $count=$count+1
    If $count=10 Then
        $count=1
        MsgBox(0, "", "Count is 10")
        NextFunction()
        Exitloop
    EndIf
Until @error

Func NextFunction()
;~  blablabla
EndFunc
The loop will not terminated without an error or ExitLoop. Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites

faldo.

In your first snippet when $count = 10 you will in order: reset $count=1; show the MsgBox(0, "", "Count is 10"); and then run NextFunction(). When NextFunction returns, the Do...Until loop will continue until $icount reaches 10 again, when the whole process repeats. This will go on until @error is set by the returning NextFunction. So continuing passes through NextFunction until it errors.

In your second snippet, when $count = 10 you do the same things in the same order, but when NextFunction returns, ExitLoop will (unsurprisingly) exit the Do...Until loop - i.e. only one pass through NextFunction. Actually, as there is only the one pass, you need not reset $count (because it is never used again within the loop) and the Until @error becomes pretty moot (as the only line which would ever trigger it is $count=$count+1 - and if that forces an error you are in big trouble :-)). In fact, you might as well use a For...Next loop.

I hope this is clear.

M23

P.S. In place of $count=$count+1, did you know you can use $count += 1? Look in the Help file under 'Language Reference - Operators'


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I thought the loop would end if i "goto" a functions outside the loop since autoit can't handle multiple "threads". I thought i had to use the "call"-function in order to still run the loop and use a function from within the loop.

I'm glad i got that answered, thanx for the quick reply guys.

Edited by faldo

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