RE: Java: Switch Or If Else

  • From: "Sina Bahram" <sbahram@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Tue, 22 Feb 2011 20:56:55 -0500

Then make a switch of switches, but yes, that's when I would say, screw all 
that stuff, make a jump table with conditionally
evaluated indexes, and call it a day.

For more info on this, see how lex and yacc generate their tables.

Take care,
Sina


-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx 
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Dave
Sent: Tuesday, February 22, 2011 8:44 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: Re: Java: Switch Or If Else

That's assuming you don't have complex conditions you're checking for;
sometimes, if/else if is the only way to go.  When code becomes
long/slightly unreadable, refactoring usually is a good idea.

On 2/22/11, Homme, James <james.homme@xxxxxxxxxxxx> wrote:
> Hi,
> Thanks, guys. When I saw Ken's example, I liked the switch better.
>
> Jim
>
> Jim Homme,
> Usability Services,
> Phone: 412-544-1810. Skype: jim.homme
> Internal recipients,  Read my accessibility
> blog<http://mysites.highmark.com/personal/lidikki/Blog/default.aspx>.
> Discuss accessibility
> here<http://collaborate.highmark.com/COP/technical/accessibility/default.aspx>.
> Accessibility Wiki: Breaking news and accessibility
> advice<http://collaborate.highmark.com/COP/technical/accessibility/Accessibility%20Wiki/Forms/AllPages.aspx>
>
> From: programmingblind-bounce@xxxxxxxxxxxxx
> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Sina Bahram
> Sent: Tuesday, February 22, 2011 1:02 PM
> To: programmingblind@xxxxxxxxxxxxx
> Subject: RE: Java: Switch Or If Else
>
> I can't agree more
>
> Switch is so superior to chains of if statements.
>
> Take care,
> Sina
>
> From: programmingblind-bounce@xxxxxxxxxxxxx
> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Ken Perry
> Sent: Tuesday, February 22, 2011 12:59 PM
> To: programmingblind@xxxxxxxxxxxxx
> Subject: RE: Java: Switch Or If Else
>
>
>
> I find switch much easier to use and read in large if else messes.  For
> example in a multi level if else like this.
>
> If (){
> If (){
> If (){
> }else{
> }
> }else{
> }
> }else{
> If (){
> If (){
> }else{
> }
> }else{
> }
> }
>
>
> Could look like this
>
> Switch ()
> Case 1:
> If (){
> }else{
> }
> Case 2:
> If (){
> }Else{
> }
>
>
>
> From: programmingblind-bounce@xxxxxxxxxxxxx
> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Homme, James
> Sent: Tuesday, February 22, 2011 12:41 PM
> To: programmingblind@xxxxxxxxxxxxx
> Subject: Java: Switch Or If Else
>
> Hi,
> Would there be a time when you would choose to use switch, and another when
> you would choose to use if else? For example, if doing it one way or the
> other would make a program easier to read. When I was just thinking about
> this, it seemed to me that if you would choose if else, you wouldn't have to
> keep remembering to put in break statements. For ease of reading, it would
> seem that the code would take less time to listen to if you would choose if
> else.
>
> Thanks.
>
> Jim
> Jim Homme,
> Usability Services,
> Phone: 412-544-1810. Skype: jim.homme
> Internal recipients,  Read my accessibility
> blog<http://mysites.highmark.com/personal/lidikki/Blog/default.aspx>.
> Discuss accessibility
> here<http://collaborate.highmark.com/COP/technical/accessibility/default.aspx>.
> Accessibility Wiki: Breaking news and accessibility
> advice<http://collaborate.highmark.com/COP/technical/accessibility/Accessibility%20Wiki/Forms/AllPages.aspx>
>
>
> ________________________________
> This e-mail and any attachments to it are confidential and are intended
> solely for use of the individual or entity to whom they are addressed. If
> you have received this e-mail in error, please notify the sender immediately
> and then delete it. If you are not the intended recipient, you must not
> keep, use, disclose, copy or distribute this e-mail without the author's
> prior permission. The views expressed in this e-mail message do not
> necessarily represent the views of Highmark Inc., its subsidiaries, or
> affiliates.
>
__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: