How to stop loop in AutoIt?

94 views Asked by At

How to exit or not from a while loop?

This is the code:

Global $test

$choice = GUICreate("Custom MsgBox", 225, 80)
GUICtrlCreateLabel("Please select a button.", 10, 10)
Local $idYess = GUICtrlCreateButton("YES", 10, 50, 65, 25)
Local $idNoo = GUICtrlCreateButton("NON", 80, 50, 65, 25)
Local $idExitt = GUICtrlCreateButton("EXIT", 150, 50, 65, 25)
GUISetState(@SW_SHOW, $choice)

Local $iMsgBoxAnswer = 1, $bLoop = True

While $bLoop
    Switch GUIGetMsg()
        Case $idYess
            ConsoleWrite("$idYess=" & $idYess & @CRLF)

        Case $idNoo
            ConsoleWrite("$idNoo=" & $idNoo & @CRLF)

    EndSwitch

    If $iMsgBoxAnswer = 1 Then ContinueLoop

    $iMsgBoxAnswer = MsgBox(4100, "MsgBox", "Are you sure you want to close the program?", 3)
    Select
        Case $iMsgBoxAnswer = 6 ;Yes
            ConsoleWrite("- bye bye" & @CRLF)
            $bLoop = False
    EndSelect
WEnd 
      
Global $num = 1    
    
While 1
                                            
  Switch $num
    Case "1"
        MsgBox(0, '', 'Number 1')
        ExitLoop 
  EndSwitch
Wend

Why isn't the 2nd working?

And why does it work after have click on exit on first loop?

1

There are 1 answers

0
Xenobiologist On

Is this what you want?

#include <MsgBoxConstants.au3>


$choice = GUICreate("Custom MsgBox", 225, 80)
GUICtrlCreateLabel("Please select a button.", 10, 10)
Local $idYess = GUICtrlCreateButton("YES", 10, 50, 65, 25)
Local $idNoo = GUICtrlCreateButton("NON", 80, 50, 65, 25)
Local $idExitt = GUICtrlCreateButton("EXIT", 150, 50, 65, 25)
GUISetState(@SW_SHOW, $choice)

Local $iMsgBoxAnswer = 1

While 1
    Switch GUIGetMsg()
        Case $idYess
            ConsoleWrite("$idYess=" & $idYess & @CRLF)
            _reallyExit()
        Case $idNoo
            ConsoleWrite("$idNoo=" & $idNoo & @CRLF)

        Case $idExitt
            ConsoleWrite("$idExitt=" & $idExitt & @CRLF)
            _reallyExit()
    EndSwitch
WEnd

Func _reallyExit()
    $iMsgBoxAnswer = MsgBox(4100, "MsgBox", "Are you sure you want to close the program?", 3)
    If $iMsgBoxAnswer = $IDYES Then
        ConsoleWrite("- bye bye" & @CRLF)
        Exit
    EndIf
EndFunc   ;==>_reallyExit