Page 1 of 1

Switch/Case Functionalisation?

Posted: 24 Jul 2020, 07:22
by Kapitano
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?

Re: Switch/Case Functionalisation?

Posted: 25 Jul 2020, 03:44
by lexikos
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.

Re: Switch/Case Functionalisation?

Posted: 25 Jul 2020, 07:27
by SOTE
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.