AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Case/Switch
Goto page Previous  1, 2
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
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...

PostPosted: Thu Feb 23, 2006 11:19 am    Post subject: Re: Case/Switch Reply with quote

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
View user's profile Send private message Visit poster's website
Demokos



Joined: 28 Dec 2005
Posts: 84

PostPosted: Thu Feb 23, 2006 6:35 pm    Post subject: Reply with quote

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
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Thu Feb 23, 2006 8:59 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
slotboxed



Joined: 07 Mar 2006
Posts: 1

PostPosted: Tue Mar 07, 2006 10:34 am    Post subject: Reply with quote

It may be useful to read how php does it:
http://www.php.net/manual/en/control-structures.switch.php

and javascript:
http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Statements:switch


For breaks in nested control structures,

php uses the "break 2" style and javascript uses the "break label" style.

The "break label" isn't explained very well there. Here is a page that shows nested use and another type of use for the label:

http://www.devguru.com/Technologies/ecmascript/quickref/break.html


Here is an example of fall-through behavior (in php):
Code:

$filesizeStr = "4.37GB";
$sizevalue = (float) substr($filesizeStr, 0, -2);
$sizemult = substr($filesizeStr, -2, 1);
$bytes = 1;
switch($sizemult){
  case "G":
    $bytes *= 1024;
  case "M":
    $bytes *= 1024;
  case "K":
    $bytes *= 1024;
  default:
    $sizevalue *= $bytes;
    $bytesize = ceil($sizevalue);
}
// $bytesize = 4692251771
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Tue Mar 07, 2006 11:49 am    Post subject: Re: Case/Switch Reply with quote

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
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Tue Mar 07, 2006 6:19 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
IvanZT



Joined: 12 Jul 2007
Posts: 5

PostPosted: Thu Aug 02, 2007 1:27 pm    Post subject: Reply with quote

As I can see now, this is still not implemented?
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Thu Aug 02, 2007 3:16 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
William
Guest





PostPosted: Tue Aug 14, 2007 5:21 pm    Post subject: Reply with quote

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

PostPosted: Thu Jun 19, 2008 9:04 pm    Post subject: Reply with quote

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
View user's profile Send private message
Dra_Gon



Joined: 25 May 2007
Posts: 208

PostPosted: Wed Aug 13, 2008 7:51 pm    Post subject: Reply with quote

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 Wink .

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
View user's profile Send private message Send e-mail
Guest






PostPosted: Thu Aug 14, 2008 2:19 am    Post subject: Reply with quote

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

PostPosted: Thu Aug 14, 2008 7:50 pm    Post subject: Reply with quote

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 Wink !

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
View user's profile Send private message Send e-mail
Dra_Gon



Joined: 25 May 2007
Posts: 208

PostPosted: Fri Aug 15, 2008 12:48 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group