 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
JSLover
Joined: 20 Dec 2004 Posts: 542 Location: LooseChange911.com... the WTC attacks were done by the US Gov't... the official story is a lie...
|
Posted: Thu Feb 23, 2006 11:19 am Post subject: Re: Case/Switch |
|
|
| Demokos wrote: | | For the JSlover "solution", I think it's, as we say in our beautifull country...(a plaster on a wooden leg) (Sorry JSLover, absolutely no offense !!!) |
...I didn't post it as a "solution"...as if I didn't want a real syntax...I want a real syntax (like C)...I just posted that cuz it works...
| Demokos wrote: | | I can't see how...can be more readable than... |
...between those 2, I like my workaround better...but C syntax is more like...
| Code: | switch(msg){
case WM_CLOSE:
msgbox, no!
break
case WM_QUIT:
msgbox, still, no!
break
case WM_PAINT:
msgbox, you! paint yourself! I'm not doing it.
break
default:
msgbox, give up eh?
break
} |
...C syntax don't cover anything but "equals"...but..."Case = Something"...is ambiguous...are you assigning the Case variable or using it in a Switch-Case?
Possible syntax?...
| Code: | switch(msg){
case in WM_CLOSE,WM_QUIT: ;take matchlist as an expression?
msgbox, no!
break
case in "WM_CLOSE,WM_QUIT": ;make matchlist a string match?
msgbox, no!
break
case in "WM_CLOSE","WM_QUIT": ;or this way?
msgbox, no!
break
case contains "Hi": ;contains operator
msgbox, Hi!
break
case [<operator-word>] "Hi": ;<operator-word> is optional
msgbox, Hi!
break
case "Hi": ;default operator is =
msgbox, Hi!
break
case between 1,10: ;less "wordy" between operator...
msgbox, Hi!
break
case between anvil,hammer: ;...with variables
msgbox, Hi!
break
case <operator-word> "Hi": ;expand with more <operator-word>s
msgbox, Hi!
break
} |
| PhiLho wrote: | | ...there is no real need for the colons... |
...a case isn't a case without a colon (plus how else can it *hit?)...loooooool....
| PhiLho wrote: | | There is no break... |
...there is no Switch-Case syntax yet, how can you say there is no break?...Chris has already said he likes break...or at least wants to do it that way...I like the cases being able to fall thru...you can Gosub if what you are doing requires a loop/break...or the inner break could just automatically break the loop & not the case. _________________
Home • Click image! • Blog |
|
| Back to top |
|
 |
Demokos
Joined: 28 Dec 2005 Posts: 84
|
Posted: Thu Feb 23, 2006 6:35 pm Post subject: |
|
|
I'll try to be short !!!
@PhiLho : as you I think If ... Else If is actually sufficent and Switch|Select ... Case not necessary, but I think it can be usefull for a concise and more readable code. No more no less.
- Ok to have Case Droopy instead of Case = Droopy and to have Case not Droopy too...
- For the break I think it can be an option : use break if you want to skip the other tests, for example.
@JSLover : once again there wasn't anything in my mind to offense you and I hope it wasn't the case. But I think that between "Else If Case" and "Else If" I prefer the second one, and between "If ... Else If" and "Switch/Case" I prefer the second one. That's all... So if we have the Case syntax it will be a good thing, if not never mind we will continue to use If ... Else If without any problem.
for your syntax proposal, I am OK with it with some little changes : | Code: | switch(msg)
{
case "Hi", msgbox, Hi! ;it is possible to have a one line Case
case in WM_CLOSE,WM_QUIT ;no need of double point
{ ;If there are several instructions, we use brackets as usual in AHK
Gosub, SomeLabel ;if the condition is OK the code is executed
msgbox, no! ;and the other tests are made (no break instruction)
}
case between anvil,hammer
{
msgbox, no! ;If if the condition is OK the code is executed
break ;with the break instruction all the others tests are skipped
} ;of course if the condition is not OK, no break...
case contains "Hi" ;And so on...
{
msgbox, no!
break
}
default, msgbox, Ho! ;Optional : if none of the condtions above are met [and without break instruction], do that...
} | I don't know if it is in the Basic, or C, or any programming language spirit, but it is my proposal.
But again in my mind it would be nice but it is not urgent and not necessary.
We can use AHK without that and there are things more usefull to do before that. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Thu Feb 23, 2006 8:59 pm Post subject: |
|
|
Thanks for the syntax ideas; I've made a note to read this topic again when the time comes.
As some said, I tend to agree that this is a slightly lower priority than it used to be. However, I'm still leaning toward adding it at some point. |
|
| Back to top |
|
 |
slotboxed
Joined: 07 Mar 2006 Posts: 1
|
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Tue Mar 07, 2006 11:49 am Post subject: Re: Case/Switch |
|
|
| JSLover wrote: | | ...a case isn't a case without a colon (plus how else can it *hit?)...loooooool.... |
Is it a pun? I don't get it...
| JSLover wrote: | | PhiLho wrote: | | There is no break... |
...there is no Switch-Case syntax yet, how can you say there is no break? |
My remark was on the syntax proposal of Demokos. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Tue Mar 07, 2006 6:19 pm Post subject: |
|
|
| Thanks for the nice links and info. I do prefer to model AHK syntax after existing languages, especially when they have a particularly easy and useful syntax. |
|
| Back to top |
|
 |
IvanZT
Joined: 12 Jul 2007 Posts: 5
|
Posted: Thu Aug 02, 2007 1:27 pm Post subject: |
|
|
| As I can see now, this is still not implemented? |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Thu Aug 02, 2007 3:16 pm Post subject: |
|
|
since AHK 2.0 has not been released - that would appear to be true. _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Last edited by engunneer on Thu Aug 14, 2008 6:08 am; edited 1 time in total |
|
| Back to top |
|
 |
William Guest
|
Posted: Tue Aug 14, 2007 5:21 pm Post subject: |
|
|
I prefer 'others' to 'default'.
1. the 'others' is way existential and lowercase.*
2. Default could be interpreted as "always applied in addition to these cases"
3. Default may be misleading, because it can be made to handle a remote possibility.
-William
*Lowercase def.: everything that uppercase isn't.[/u] |
|
| Back to top |
|
 |
argneo
Joined: 14 Sep 2007 Posts: 124
|
Posted: Thu Jun 19, 2008 9:04 pm Post subject: |
|
|
I was just looking for something like this to use in the multi-language auto-corrector... Will it be reviewed sometime soon? _________________
WoW |
|
| Back to top |
|
 |
Dra_Gon
Joined: 25 May 2007 Posts: 208
|
Posted: Wed Aug 13, 2008 7:51 pm Post subject: |
|
|
Yo, is this one still on the board? Or is there a current workaround {i.e. function or such} which can be used?
I've used the "Select...Case...EndSelect" through IBDev and found it MUCH more useful than the "If...Else If". You'd think they would be about the same, but it just seems much clearer to me with the SCE. Just my 2 cents worth .
Ciao,
Dra'Gon _________________
For a good laugh {hopefully} >> megamatts.50megs.com
SciFi/Fantasy Short Stories I wrote {StohlerWorlds I} >>
http://www.mediafire.com/?2yisetu0jud |
|
| Back to top |
|
 |
Guest
|
Posted: Thu Aug 14, 2008 2:19 am Post subject: |
|
|
| Dra_Gon wrote: | | Yo, is this one still on the board? |
...is this what still on board? My Switch-Case workaround? Yes...
...I intended to move it into Base.ahi a long time ago, but haven't...
| Dra_Gon wrote: | | ...& found it MUCH more useful than the "If...Else If". |
...do you mean..."if (a=1) else if (a=2)"...or my..."switch(a) if case(1) else if case(2)"...my workaround uses if...else if, but only cuz it has too...
| Dra_Gon wrote: | | ...but it just seems much clearer to me with the SCE. |
...Select...EndSelect...or any of the Func...EndFunc...constructs annoy me...I like braces...{ } to mark the begin & end... |
|
| Back to top |
|
 |
Dra_Gon
Joined: 25 May 2007 Posts: 208
|
Posted: Thu Aug 14, 2008 7:50 pm Post subject: |
|
|
Oh, by SCE I just meant that style. Using the brackets instead of EndSelect is just fine by me. And I simply prefer to use the Select..Case rather than the If...Else If myself. I understand that since AHK doesn't have it SOMEONE had to use the If...Else If kinda thing as a workaround. I'm just glad I didn't have to try to figure it out !
THANKS! I'll check 'em out.
Ciao,
Dra'Gon _________________
For a good laugh {hopefully} >> megamatts.50megs.com
SciFi/Fantasy Short Stories I wrote {StohlerWorlds I} >>
http://www.mediafire.com/?2yisetu0jud |
|
| Back to top |
|
 |
Dra_Gon
Joined: 25 May 2007 Posts: 208
|
Posted: Fri Aug 15, 2008 12:48 am Post subject: |
|
|
Oh, now I see what you meant by yours using the If...Else If. Dang! Well, it does seem to clean it up a bit better. I'll use it and try to figure something as a function, just not sure how yet.
Ciao,
Dra'Gon _________________
For a good laugh {hopefully} >> megamatts.50megs.com
SciFi/Fantasy Short Stories I wrote {StohlerWorlds I} >>
http://www.mediafire.com/?2yisetu0jud |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|