Jump to content

Recommended Posts

Posted

Hey guys, iv been running multiple tests to learn the While Loop completely but i have a few concerns lol sorry :(

Here is an example of what I am trying:

 

HotKeySet("^!x", "MyExit")

While 1
   If PixelSearch() ;for example: a blue color from a notification from Facebook
    If not (@error) then 
    ;if pixel is found, do this until pixel is not there 

    Else
        While 1
            If PixelSearch() ;for example: a white color from a Gmail notification when you receive an email
            If not (@error) then
             ;if pixel is found, do this until pixel is not there
             Else
                Exitloop ;i placed this exitloop so it will go back to continue searching for the blue pixel.
             EndIf  
        WEnd
     EndIf
WEnd

Func MyExit()
    Exit 
EndFunc

 

When I try this, it doesn't return to loop 1 but I am not sure if the reason why is not going back to loop 1 is due to the ExitLoop I placed... maybe I should use something "Do, Until" instead of While?

 

 

 

Posted (edited)

Sorry, I was just trying to understand how it works.

I will try to post a proper example when I get home.

 

EDIT to avoid double post: Can you answer me a quick question?  Whats the difference between using While 1 vs While True ?  is it the same?

 

Thanks

Edited by scorp2k19
Posted (edited)
HotKeySet("^!x", "MyExit")

While 1
   If PixelSearch() ;for example: a blue color from a notification from Facebook
    If not (@error) then 
    ;if pixel is found, do this until pixel is not there 

    Else
        While 1
            If PixelSearch() ;for example: a white color from a Gmail notification when you receive an email
            If not (@error) then
            ConsoleWrite("white pixel found" & @crlf)
             ;if pixel is found, do this until pixel is not there
             Else
                ConsoleWrite("returning to main loop" & @crlf)
                Exitloop ;i placed this exitloop so it will go back to continue searching for the blue pixel.
             EndIf  
        WEnd
     EndIf
WEnd

Func MyExit()
    Exit 
EndFunc

This way you can see what's happening.

While 1 = While True

Edited by Dana
Posted
8 minutes ago, Dana said:

While 1 = While True

Saying True makes so more sense and makes your code much more readable (especially to me... slightly dyslexic, I always think 0 is true). It's good practice, see: magic numbers

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

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