Code: Select all
case 1 && 2 :
msgbox
Code: Select all
case 3:
Msgbox
case 4:
do case 3
Code: Select all
case 1 && 2 :
msgbox
Code: Select all
case 3:
Msgbox
case 4:
do case 3
Any expression is fine.Each case may list up to 20 values. Each value must be an expression, but can be a simple one such as a literal number, quoted string or variable.
Source: Switch - Syntax & Usage | AutoHotkey v2
Code: Select all
#Requires AutoHotkey v2.0
Switch {
Case 1 && 2:
MsgBox
}
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance Force
var := "0x0003"
; A.
switch (var)
{
default:
case 1:
case 2:
case 3,4: msgbox var
}
; B.
switch
{
default:
case (var==1):
case (var==2):
case (var==3||var==4): msgbox var
}
; C.
switch (var)
{
case 1:
case 2:
default:
switch
{
case (format("{:d}",var)~="D)^(3|4)$"): msgbox var
default:
}
}
sorry I didn't know you could use && , || expressions in switch cases because most examples are with IF statements,also I'm not that good.mikeyww wrote: ↑27 Apr 2024, 14:39Any expression is fine.Each case may list up to 20 values. Each value must be an expression, but can be a simple one such as a literal number, quoted string or variable.
Source: Switch - Syntax & Usage | AutoHotkey v2
I'm puzzled about why you want to ask this question instead of testing your idea in your script. The test requires about 45 seconds.
Code: Select all
#Requires AutoHotkey v2.0 Switch { Case 1 && 2: MsgBox }
Seven0528 wrote: ↑27 Apr 2024, 22:25Code: Select all
#Requires AutoHotkey v2.0 #SingleInstance Force var := "0x0003" ; A. switch (var) { default: case 1: case 2: case 3,4: msgbox var } ; B. switch { default: case (var==1): case (var==2): case (var==3||var==4): msgbox var } ; C. switch (var) { case 1: case 2: default: switch { case (format("{:d}",var)~="D)^(3|4)$"): msgbox var default: } }