Jump to content

Recommended Posts

Posted

that means while 1 exists, it's an infinite loop.

so essentially it's until 1<>1

I always use:

$hellFreezesOver = False

do
;stuff
until $hellFreezesOver

... which does exactly the same but explains it better :shocked:

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Posted (edited)

The why of it is that sometimes we just want to run a short throwaway script for a few minutes perhaps as a debugging aid and then it can just be killed by clicking Tools>Stop. For instance this little script by JdeB prints to the console window at the bottom of the editor and shows the className of what's under the mouse.

While 1
    ConsoleWrite('ControlGetFocus("") = ' & ControlGetFocus("") & @crlf )
    sleep(1000)
WEnd

And sometimes it is used for things like a GUI Message Loop. See the example at the bottom of the GUIGetMsg help page.

jh

Edited by hmsSurprise
Posted

I always use:

$hellFreezesOver = False

do
;stuff
until $hellFreezesOver

... which does exactly the same but explains it better :shocked:

Just to be thorough: While/WEnd and Do/Until perform their tests at different times. So this example is not equivalent to the original post's.

A While loop does the test BEFORE running the code inside the loop. So if the test condition is false to begin with, the code in the loop never gets run.

A Do loop does the test AFTER running the code in the loop. So the code is always run at least once, even if the test condition was always false.

:(

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
Posted (edited)

Just to be thorough: While/WEnd and Do/Until perform their tests at different times. So this example is not equivalent to the original post's.

A While loop does the test BEFORE running the code inside the loop. So if the test condition is false to begin with, the code in the loop never gets run.

A Do loop does the test AFTER running the code in the loop. So the code is always run at least once, even if the test condition was always false.

:shocked:

I know the difference, but thanks for explaining. Actually in this case what I meant by 'it does the same', was that they both will end up being an infinite loop if not exited in some way like ExitLoop or a change of $hellFreezesOver (in my example that is). But you are right ofcourse.

You could rewrite it to a while loop and still retain my histerically funny contradictionary statement by doing:

$hellFrozeOver = False
While not $hellFrozeOver
; stuff
WEnd

:(

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Posted

It was for qwertylol's benefit.

I did think yours was funny, and you inspired me to use this just a little while later in another thread:

$Pigs_Fly = False
Do
        ; Loop forever
Until $Pigs_Fly

:shocked:

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

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