Switch/Case Functionalisation?

Discuss the future of the AutoHotkey language
Kapitano
Posts: 13
Joined: 07 Sep 2019, 10:58

Switch/Case Functionalisation?

24 Jul 2020, 07:22

As of a118, this works:

Code: Select all

i_Number := 1
Switch i_Number {
	Case 1:
		MsgBox("Number is One")
		MsgBox("Yes, definitely One")
	Case 2: ; Do Nothing
	Case 3: MsgBox("Number is Three")
}
...and this, doesn't:

Code: Select all

i_Number := 1
Switch i_Number {
	Case 1 {
		MsgBox("Number is One")
		MsgBox("Yes, definitely One")
	}
	Case 2 ; Do Nothing
	Case 3 MsgBox("Number is Three")
}
But, with the recent removal of Gosub, and the consequent need to rewrite subroutines as functions, are Case labels planned for removal? Indeed, is the plan to phase out all labels, and have all blocks between braces?
lexikos
Posts: 7085
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Switch/Case Functionalisation?

25 Jul 2020, 03:44

No.
Case 3 MsgBox("Number is Three")
This would never work the way you think. 3 MsgBox("Number is Three") is a valid case expression. This is part of the reason I chose for switch-case to use colons, rather than just line endings.
SOTE
Posts: 1079
Joined: 15 Jun 2015, 06:21

Re: Switch/Case Functionalisation?

25 Jul 2020, 07:27

Kapitano wrote:
24 Jul 2020, 07:22
But, with the recent removal of Gosub, and the consequent need to rewrite subroutines as functions, are Case labels planned for removal?
Depending on the level and style of the script writer, rewriting AHK v1 to AHK v2 would seem to be a major problem or create various levels of confusion for many AHK v1 users. AHK v2 is "experimental" in many regards and not for production, I think that's where a AHK user might be very careful on how they use such scripts. Also, it seems like trying to ask for a specific road map would remove various levels of flexibility in the direction of the design.

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 8 guests