Re: [Flashcoders] ActionScript switch/default syntax and interpretation

2006-12-22 Thread Mark Lapasa

Good question. Great thread. -mL

T. Michael Keesey wrote:

On 12/21/06, Wagner Amaral <[EMAIL PROTECTED]> wrote:

The last break on default is considered by some to be a coding
standard, by which you explicitly say you wanted to leave the default
block empty, and not just simply forgot.
Also, if unadvised people add code at the end of the switch without
realizing the missing break, your default will fall-through.


Good point. Well, in any event, it doesn't hurt, I suppose.




___
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] ActionScript switch/default syntax and interpretation

2006-12-21 Thread T. Michael Keesey

On 12/21/06, Wagner Amaral <[EMAIL PROTECTED]> wrote:

The last break on default is considered by some to be a coding
standard, by which you explicitly say you wanted to leave the default
block empty, and not just simply forgot.
Also, if unadvised people add code at the end of the switch without
realizing the missing break, your default will fall-through.


Good point. Well, in any event, it doesn't hurt, I suppose.
--
T. Michael Keesey
The Dinosauricon: http://dino.lm.com
Parry & Carney: http://parryandcarney.com
ISPN Forum: http://www.phylonames.org/forum/
___
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] ActionScript switch/default syntax and interpretation

2006-12-21 Thread Rich Rodecker

yeah it seems feels delibrately awkward to leave off the last
break...sorta like writing a one line if.



On 12/21/06, Andy Herrman <[EMAIL PROTECTED]> wrote:

Yea, the last break is unecessary, but I think it's a good idea to put
there.  Just to have the habit of already remembering to put breaks at
the end of case statements (I've forgotten a couple times and went
nuts looking for the bug).  And as Wagner mentioned, it protects
against people adding more cases to the end of the switch statement.

   -Andy

On 12/21/06, Wagner Amaral <[EMAIL PROTECTED]> wrote:
> The last break on default is considered by some to be a coding
> standard, by which you explicitly say you wanted to leave the default
> block empty, and not just simply forgot.
> Also, if unadvised people add code at the end of the switch without
> realizing the missing break, your default will fall-through.
>
>
>
> On 12/21/06, T. Michael Keesey <[EMAIL PROTECTED]> wrote:
> > On 12/21/06, Julien Vignali <[EMAIL PROTECTED]> wrote:
> > >
> > > switch(condition){
> > >   case A:
> > >   break;
> > >   case B:
> > >   break;
> > >   default:
> > > // not mendatory but should always be the last statement
> > >   break;
> > > }
> >
> > That last break is actually unnecessary. The breaks are only to keep
> > it from going to the next case. In some (pretty rare) cases, you may
> > not even want to do that, e.g.:
> >
> > switch(a) {
> > case 0:
> >// Does this if a == 0
> >   break;
> > case 1 :
> >// Does this if a == 1.
> > case 2 :
> >// Does this if a == 1 or a == 2.
> > default :
> >   // Does this if a is anything but 0.
> > }
> >
> > --
> > T. Michael Keesey
> > The Dinosauricon: http://dino.lm.com
> > Parry & Carney: http://parryandcarney.com
> > ISPN Forum: http://www.phylonames.org/forum/
> > ___
> > [email protected]
> > To change your subscription options or search the archive:
> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >
> > Brought to you by Fig Leaf Software
> > Premier Authorized Adobe Consulting and Training
> > http://www.figleaf.com
> > http://training.figleaf.com
> >
> ___
> [email protected]
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
___
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] ActionScript switch/default syntax and interpretation

2006-12-21 Thread Andy Herrman

Yea, the last break is unecessary, but I think it's a good idea to put
there.  Just to have the habit of already remembering to put breaks at
the end of case statements (I've forgotten a couple times and went
nuts looking for the bug).  And as Wagner mentioned, it protects
against people adding more cases to the end of the switch statement.

  -Andy

On 12/21/06, Wagner Amaral <[EMAIL PROTECTED]> wrote:

The last break on default is considered by some to be a coding
standard, by which you explicitly say you wanted to leave the default
block empty, and not just simply forgot.
Also, if unadvised people add code at the end of the switch without
realizing the missing break, your default will fall-through.



On 12/21/06, T. Michael Keesey <[EMAIL PROTECTED]> wrote:
> On 12/21/06, Julien Vignali <[EMAIL PROTECTED]> wrote:
> >
> > switch(condition){
> >   case A:
> >   break;
> >   case B:
> >   break;
> >   default:
> > // not mendatory but should always be the last statement
> >   break;
> > }
>
> That last break is actually unnecessary. The breaks are only to keep
> it from going to the next case. In some (pretty rare) cases, you may
> not even want to do that, e.g.:
>
> switch(a) {
> case 0:
>// Does this if a == 0
>   break;
> case 1 :
>// Does this if a == 1.
> case 2 :
>// Does this if a == 1 or a == 2.
> default :
>   // Does this if a is anything but 0.
> }
>
> --
> T. Michael Keesey
> The Dinosauricon: http://dino.lm.com
> Parry & Carney: http://parryandcarney.com
> ISPN Forum: http://www.phylonames.org/forum/
> ___
> [email protected]
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
___
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] ActionScript switch/default syntax and interpretation

2006-12-21 Thread Wagner Amaral

The last break on default is considered by some to be a coding
standard, by which you explicitly say you wanted to leave the default
block empty, and not just simply forgot.
Also, if unadvised people add code at the end of the switch without
realizing the missing break, your default will fall-through.



On 12/21/06, T. Michael Keesey <[EMAIL PROTECTED]> wrote:

On 12/21/06, Julien Vignali <[EMAIL PROTECTED]> wrote:
>
> switch(condition){
>   case A:
>   break;
>   case B:
>   break;
>   default:
> // not mendatory but should always be the last statement
>   break;
> }

That last break is actually unnecessary. The breaks are only to keep
it from going to the next case. In some (pretty rare) cases, you may
not even want to do that, e.g.:

switch(a) {
case 0:
   // Does this if a == 0
  break;
case 1 :
   // Does this if a == 1.
case 2 :
   // Does this if a == 1 or a == 2.
default :
  // Does this if a is anything but 0.
}

--
T. Michael Keesey
The Dinosauricon: http://dino.lm.com
Parry & Carney: http://parryandcarney.com
ISPN Forum: http://www.phylonames.org/forum/
___
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] ActionScript switch/default syntax and interpretation

2006-12-21 Thread Rich Rodecker

yeah, that technique is called a "fall-through", it's very handy, I
use it all the time.

http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=1244.html



On 12/21/06, T. Michael Keesey <[EMAIL PROTECTED]> wrote:

On 12/21/06, Julien Vignali <[EMAIL PROTECTED]> wrote:
>
> switch(condition){
>   case A:
>   break;
>   case B:
>   break;
>   default:
> // not mendatory but should always be the last statement
>   break;
> }

That last break is actually unnecessary. The breaks are only to keep
it from going to the next case. In some (pretty rare) cases, you may
not even want to do that, e.g.:

switch(a) {
case 0:
   // Does this if a == 0
  break;
case 1 :
   // Does this if a == 1.
case 2 :
   // Does this if a == 1 or a == 2.
default :
  // Does this if a is anything but 0.
}

--
T. Michael Keesey
The Dinosauricon: http://dino.lm.com
Parry & Carney: http://parryandcarney.com
ISPN Forum: http://www.phylonames.org/forum/
___
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] ActionScript switch/default syntax and interpretation

2006-12-21 Thread T. Michael Keesey

On 12/21/06, Julien Vignali <[EMAIL PROTECTED]> wrote:


switch(condition){
  case A:
  break;
  case B:
  break;
  default:
// not mendatory but should always be the last statement
  break;
}


That last break is actually unnecessary. The breaks are only to keep
it from going to the next case. In some (pretty rare) cases, you may
not even want to do that, e.g.:

switch(a) {
case 0:
  // Does this if a == 0
 break;
case 1 :
  // Does this if a == 1.
case 2 :
  // Does this if a == 1 or a == 2.
default :
 // Does this if a is anything but 0.
}

--
T. Michael Keesey
The Dinosauricon: http://dino.lm.com
Parry & Carney: http://parryandcarney.com
ISPN Forum: http://www.phylonames.org/forum/
___
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] ActionScript switch/default syntax and interpretation

2006-12-21 Thread R�kos Attila

Oh, I'm sorry, I mistyped the expected result in my last post: it
should be "1".

  Attila

___
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] ActionScript switch/default syntax and interpretation

2006-12-21 Thread R�kos Attila

Yes, it's a valid script (except switch(var) instead of switch(v)),
and the expected result is "default", since the documentation states
that "a default case statement does not have to be last in the list".

s> Is this valid ActionScript ?
s> 
s>  var v = 1;
s>  switch (var)
s>  {
s>  default:
s>  trace("default");
s>  break;
s>  case 1:
s>  trace("1");
s>  break;
s>  }
s> 
s> What is expected to be traced ?


___
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] ActionScript switch/default syntax and interpretation

2006-12-21 Thread Magnus Askenbäck

switch (v)

.m



strk wrote:


Is this valid ActionScript ?

var v = 1;
switch (var)
{
default:
trace("default");
break;
case 1:
trace("1");
break;
}

What is expected to be traced ? 


--strk;
___
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


 



___
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] ActionScript switch/default syntax and interpretation

2006-12-21 Thread Mark Winterhalder

What is expected to be traced ?


I would /expect/ it to trace "default".
The reason why I think so is that a) the break is necessary and I'd
expect it to trace "default" and then "1" without it, and b):

case 1:
case 2:
trace( "one or two" );
break;

...works, too.

However, I don't have the Adobe compiler to test (guessing that is
what you're after), so maybe somebody else could try it and confirm.

Mark


On 12/21/06, strk <[EMAIL PROTECTED]> wrote:

Is this valid ActionScript ?

var v = 1;
switch (var)
{
default:
trace("default");
break;
case 1:
trace("1");
break;
}

What is expected to be traced ?

--strk;
___
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] ActionScript switch/default syntax and interpretation

2006-12-21 Thread Julien Vignali

First, you have a typo in your switch(): you wrote switch(var) instead of
switch(v).

Second, to avoid any unpredictable result from a switch(), this statement
should look like (according to the MM docs) :

switch(condition){
 case A:
 break;
 case B:
 break;
 default:
   // not mendatory but should always be the last statement
 break;
}

Moreover, another good practice is to type variables because the case:
statement uses the strict equality (===) to evaluate the result of the
condition.

So, returning to your problem :

var v:Number = 1;
switch(v){
 case "1":
   trace("case string 1");
 break;
 case 1:
   trace("case number 1");
 break;
 default:
   trace("default");
 break;
}

Obviously outputs : "case number 1".

What result do you have?



2006/12/21, strk <[EMAIL PROTECTED]>:


Is this valid ActionScript ?

var v = 1;
switch (var)
{
default:
trace("default");
break;
case 1:
trace("1");
break;
}

What is expected to be traced ?

--strk;
___
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com





--
Julien Vignali
___
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com