RE: [Flashcoders] switch statement more efficient than if...else?

2008-06-26 Thread Merrill, Jason
One thing that nobody who writes switch statements seemed to know (me included) is you can (and, apparently, should) write them like this: I knew that. I guess you missed this in my post. After I showed the switch statement, I said, (or the same thing above but with brackets) Jason Merrill

[Flashcoders] switch statement more efficient than if...else?

2008-06-25 Thread Allandt Bik-Elliott (Receptacle)
Hi guys quick question that came up in a conversation I had the other day - are switch statements more or less efficient than a series of if...else statements in either AS2 or AS3? I'd always thought that the most efficient was the switch al.z

Re: [Flashcoders] switch statement more efficient than if...else?

2008-06-25 Thread Paul Andrews
- Original Message - From: Allandt Bik-Elliott (Receptacle) [EMAIL PROTECTED] To: flashcoders flashcoders@chattyfig.figleaf.com Sent: Wednesday, June 25, 2008 3:12 PM Subject: [Flashcoders] switch statement more efficient than if...else? Hi guys quick question that came up

Re: [Flashcoders] switch statement more efficient than if...else?

2008-06-25 Thread eric e. dolecki
Switch/case is a bit quicker. On Wed, Jun 25, 2008 at 10:12 AM, Allandt Bik-Elliott (Receptacle) [EMAIL PROTECTED] wrote: Hi guys quick question that came up in a conversation I had the other day - are switch statements more or less efficient than a series of if...else statements in either

Re: [Flashcoders] switch statement more efficient than if...else?

2008-06-25 Thread Kenneth Kawamoto
One thing worth noting is switch statement uses strict equality (===) therefore it's not exactly the same as if/else with equality (==). Kenneth Kawamoto http://www.materiaprima.co.uk/ Paul Andrews wrote: Hi guys quick question that came up in a conversation I had the other day - are

Re: [Flashcoders] switch statement more efficient than if...else?

2008-06-25 Thread Juan Pablo Califano
I doubt there's a noticeable difference between a switch and a series of if /else if statements. In AS 3.0 bytecode, though, switches and equivalent conditionals are not necessarily compiled into the same bytecode. In fact, there's a lookupswitch instruction (opcode 0x1b). Of course, any switch

Re: [Flashcoders] switch statement more efficient than if...else?

2008-06-25 Thread Allandt Bik-Elliott (Receptacle)
hey thanks for all of your responses al.z On 25 Jun 2008, at 16:24, Juan Pablo Califano wrote: I doubt there's a noticeable difference between a switch and a series of if /else if statements. In AS 3.0 bytecode, though, switches and equivalent conditionals are not necessarily compiled

Re: [Flashcoders] switch statement more efficient than if...else?

2008-06-25 Thread Mark Winterhalder
I'd always thought that the most efficient was the switch I know that the haXe compiler uses a jump table, I'm not sure about the AS3 compiler. But as already mentioned there is an extra opcode for switch, and even if the compiler doesn't a jump table, it might use one in the future. So, switch

Re: [Flashcoders] switch statement more efficient than if...else?

2008-06-25 Thread Rich Shupe
Actually, tt is my (perhaps wrong) understanding that this is not the case. In the past, both Macromedia and Adobe sources have stated that switch does not offer a performance boost--just readability and functionality (optional break lines) enhancements over if statements. I have been wrong many

Re: [Flashcoders] switch statement more efficient than if...else?

2008-06-25 Thread Cedric Muller
and switch on Number ? :P I read somewhere that Number was quicker than int though I still can't believe it cedric I'd always thought that the most efficient was the switch I know that the haXe compiler uses a jump table, I'm not sure about the AS3 compiler. But as already mentioned

Re: [Flashcoders] switch statement more efficient than if...else?

2008-06-25 Thread Steven Sacks
I disagree that switch statements are more readable than if else statements, at least if you put your braces on their own lines. if (true) { // something } else if (true) { // something else } else if (true) { // yet another outcome } I don't think either is more readable than the

RE: [Flashcoders] switch statement more efficient than if...else?

2008-06-25 Thread Merrill, Jason
I disagree that switch statements are more readable than if else statements, at least if you put your braces on their own lines. I wouldn't disagree, but I think it's more about personal preference. Maybe it's just aesthetics, but I prefer: switch(b) { case apple: do

RE: [Flashcoders] switch statement more efficient than if...else?

2008-06-25 Thread Kerry Thompson
Steven Sacks wrote: I disagree that switch statements are more readable than if else statements, at least if you put your braces on their own lines. I'm a die-hard switch/case guy, but I agree with Steven on this. Neither is inherently easier or harder to read. Of course, I personally prefer

Re: [Flashcoders] switch statement more efficient than if...else?

2008-06-25 Thread eric e. dolecki
better way than nested switches that are 3-4 pages long = if/else statements ;) On Wed, Jun 25, 2008 at 11:25 PM, Kerry Thompson [EMAIL PROTECTED] wrote: Steven Sacks wrote: I disagree that switch statements are more readable than if else statements, at least if you put your braces on

Re: [Flashcoders] switch statement more efficient than if...else?

2008-06-25 Thread Steven Sacks
One thing that nobody who writes switch statements seemed to know (me included) is you can (and, apparently, should) write them like this: switch (n) { case 0: { foo(); break; } case 1: { bar(); return; } case 2: { baz();