AutoHotkey Community

It is currently May 25th, 2012, 1:47 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 45 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: Case/Switch
PostPosted: February 23rd, 2006, 11:19 am 
Offline
User avatar

Joined: December 20th, 2004, 12:19 pm
Posts: 794
Location: LooseChange911.com Ask Questions, Demand Answers █ The WTC bldgs █ shouldn't have fallen █ that fast
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.

_________________
AutoHotkey-Hotstring.ahk - Helping the world spell "AutoHotkey" correctly! (btw, it's a lowercase k!)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 23rd, 2006, 6:35 pm 
Offline

Joined: December 28th, 2005, 10:46 am
Posts: 99
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 23rd, 2006, 8:59 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2006, 10:34 am 
Offline

Joined: March 7th, 2006, 10:09 am
Posts: 1
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Case/Switch
PostPosted: March 7th, 2006, 11:49 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
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.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2006, 6:19 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 2nd, 2007, 1:27 pm 
Offline

Joined: July 12th, 2007, 9:53 pm
Posts: 5
As I can see now, this is still not implemented?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 2nd, 2007, 3:16 pm 
Online
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8649
Location: Salem, MA
since AHK 2.0 has not been released - that would appear to be true.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Last edited by engunneer on August 14th, 2008, 6:08 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 14th, 2007, 5:21 pm 
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]


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2008, 9:04 pm 
Offline

Joined: September 14th, 2007, 4:51 am
Posts: 220
I was just looking for something like this to use in the multi-language auto-corrector... Will it be reviewed sometime soon?

_________________
Image Search&Replace

Don't use cannon to kill mosquito


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 13th, 2008, 7:51 pm 
Offline

Joined: May 25th, 2007, 6:13 pm
Posts: 373
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

_________________
Image
For a good laugh {hopefully} >> megamatts.50megs.com

My WritersCafe profile>>
http://www.writerscafe.org/writers/BlueDragonFire/


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 14th, 2008, 2:19 am 
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...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 14th, 2008, 7:50 pm 
Offline

Joined: May 25th, 2007, 6:13 pm
Posts: 373
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

_________________
Image
For a good laugh {hopefully} >> megamatts.50megs.com

My WritersCafe profile>>
http://www.writerscafe.org/writers/BlueDragonFire/


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 15th, 2008, 12:48 am 
Offline

Joined: May 25th, 2007, 6:13 pm
Posts: 373
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

_________________
Image
For a good laugh {hopefully} >> megamatts.50megs.com

My WritersCafe profile>>
http://www.writerscafe.org/writers/BlueDragonFire/


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 14th, 2009, 6:19 pm 
I'm a little confused on how to go about using these Switch-Case scenarios? I want to use a switch case in my code, how do I do this? Thanks.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 45 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group