Keyword Reference


While...WEnd

Loop based on an expression.

While <expression>
statements
...
WEnd

Parameters

expression If the expression is true the following statements up to the WEnd statement are executed. This loop continues until the expression is false.

Remarks

While...WEnd statements may be nested.
The expression is tested before the loop is executed so the loop will be executed zero or more times.
To create an infinite loop, you can use a non-zero number as the expression.

Related

ContinueLoop, ExitLoop

Example

Example 1

#include <MsgBoxConstants.au3>

Local $i = 0
While $i <= 10
    MsgBox($MB_SYSTEMMODAL, "", "Value of $i is: " & $i)
    $i = $i + 1
WEnd

Example 2

; Set the Escape hotkey to terminate the script.
HotKeySet("{ESC}", "_Terminate")

Example()

Func Example()
    ; Initialize a Local variable.
    Local $aMgp = 0

    ; Create an endless loop, 1 will always be 1 therefore True.
    While 1
        ; Assign a Local variable the coords of the cursor (array).
        $aMgp = MouseGetPos()

        ; Display a tooltip near the cursor with its coords.
        ToolTip("x: " & $aMgp[0] & ", y: " & $aMgp[1], $aMgp[0] + 10, $aMgp[1] + 10)

        ; Avoid high CPU usage.
        Sleep(50)
    WEnd
EndFunc   ;==>Example

Func _Terminate()
    Exit
EndFunc   ;==>_Terminate