Terminate a While/Do/For loop.
ExitLoop [level]
level | [optional] The number of loop levels to exit from. The default is 1 (meaning the current loop). |
A negative level or zero value has no effect.
ExitLoop will break out of a While, Do or For loop.
ExitLoop is useful when you would otherwise need to perform error checking in both the loop-test and the loop-body.
ContinueLoop, Do, Exit, For, While
#include <MsgBoxConstants.au3>
Local $iSum = 0, $iAns = 0
While 1 ;use infinite loop since ExitLoop will get called
$iAns = InputBox("Running total=" & $iSum, _
" Enter a positive number. (A negative number exits)")
If $iAns < 0 Then ExitLoop
$iSum = $iSum + $iAns
WEnd
MsgBox($MB_SYSTEMMODAL, "", "The sum was: " & $iSum)