Jump to content

When a Loop isn't a Loop


czardas
 Share

Go to solution Solved by Bowmore,

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

It looks to me that if $bCondition = True, then test 2 will never execute.  If $bCondition is False, then both tests will execute.  In this case test 2 can be done away with no difference in how the code works.

Link to comment
Share on other sites

Oh, I haven't been reading anybody's code.  I'm just commenting on the 1st post.

Glad I could help though. :P

Edited by jaberwacky
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

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