如何在 AutoIt 中停止循环?

问题描述 投票:0回答:1

如何退出或不退出while循环?

这是代码:

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

为什么第二个不起作用?

为什么在第一个循环上单击退出后它会起作用?

autoit
1个回答
0
投票

这是你想要的吗?

#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
© www.soinside.com 2019 - 2024. All rights reserved.