Jump to content

When a Loop isn't a Loop


Go to solution Solved by Bowmore,

Recommended Posts

Posted (edited)

Yes it's part of the same module as the lines of script which surround the sequence of loops. The whole function has one purpose - to set up conditions suitable to continue on to the next phase (in another part of the script). Since all the data is readily accessible in the local scope, it seems an unecessary inconvenience to port the arguments elsewhere.

I'm not saying this approach is necessarily better, but I think it ought to be a valid option in some situations.

Edited by czardas
Posted (edited)

I would use one If-Then command with Or's for all the same reasons as  Bowmore stated in post #17.   Plus, there is no unnecessary confusing code - like a loop!.
 

Local $bCondition1 = True, $bCondition2 = True, $bCondition3 = True
Local $bCondition4 = True, $bCondition5 = false

If _
        $bCondition1 And _                     ; test 1
        $bCondition2 And _                     ; test 2
        ($bCondition3 And $bCondition4) And _  ; test 3
        $bCondition5 _                        ; test 4
        Then MsgBox(0, "", "Passed", 3)

Edit: Changed all "Or" to "And"

Edited by Malkey
Posted

Yes it's part of the same module as the lines of script which surround the sequence of loops. The whole function has one purpose - to set up conditions suitable to continue on to the next phase (in another part of the script). Since all the data is readily accessible in the local scope, it seems an unecessary inconvenience to port the arguments elsewhere.

I'm not saying this approach is necessarily better, but I think it ought to be a valid option in some situations.

It's valid without a doubt, Just remains to be seen whether it's purely an aesthetic preference in coding style or whether the are any benefits with regards efficiency.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Posted (edited)

The >inner loops can't be removed, so Malkey's suggestion is not valid. The first post is a simplification of the concept.

I have thought a little deeper about this and have come to the following conclusion (wherein lies the advantage of using Do...Until): This is intended use (although perhaps not anticipated),

Do... run the loop first ... Until (condition is met) - Do loops will always run once regardless of condition.

Others (While and For loops) test the condition first - These loops may sometimes never run.

So I conclude this to be within the realms of good practice.


@JohnOne - I doubt there would be any noticable speed gain (certainly not significant).

Edited by czardas

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...