[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Re: Nested Switch() statements



PureBytes Links

Trading Reference Links

Can you please explain me why 'switch statements are a frequent source of bugs' ? If the last CASE is a DEFAULT then all possible cases are covered. Or am I missing something in the AFL SWITCH statement ?
 
switch ( _expression_ )
{

    case constant-expression1 : statement;
    case constant-_expression_2 : statement;
    ...
    case constant-expressionN : statement;

    default : statement;

}

 
Ton.
 
----- Original Message -----
From: vlanschot
Sent: Friday, May 25, 2007 10:20 AM
Subject: [amibroker] Re: Nested Switch() statements

Personally, I found TJ's reference to the Wikipedia explanation
helpfull: http://en.wikipedia.org/wiki/Switch_statement.

One of the points it makes is that it is "easier to read and maintain
than an equivalent series of if-else statements, because it is more
concise."

However, it also warns that ". . .when implemented with fall-through,
switch statements are a frequent source of bugs among programmers new
to the switch statement."

PS

--- In amibroker@xxxxxxxxxps.com, "dmcleod1981" <dmcleod1981@...>
wrote:
>
> Tomasz
>
> We appreciate when you take the time to give us examples...however,
if
> I could ask a really lame question... what does this code do? How
> could we use it? I am sorry to say that I don't have a clue how I
> could learn and use this as I don't even know what the example is
> telling me. I am sure you roll your eyes at our code ignorance
> sometimes but us simple mortals can't pick up this stuff as fast as
> you... :)
>
> Thanks
> DM
>
> --- In amibroker@xxxxxxxxxps.com, "Tomasz Janeczko" <groups@> wrote:
> >
> > Herman,
> >
> > Here is a quick sample (for indicator):
> >
> >
> >
> > x = Param("x", 1, 1, 3, 1 );
> > y = Param("y", 10, 10, 12, 1 );
> >
> > textx = "";
> > texty = "";
> >
> > switch( x )
> > {
> > case 1:
> > {
> > textx = "x = 1";
> >
> > switch( y )
> > {
> > case 10:
> > texty = "y = 10";
> > break;
> > case 11:
> > texty = "y = 11";
> > break;
> > case 12:
> > texty = "y = 12";
> > break;
> > }
> > }
> > break;
> >
> > case 2:
> > textx = "x = 2";
> > break;
> >
> > case 3:
> > textx = "x = 3";
> > break;
> > }
> >
> > Title = textx + ", " + texty;
> >
> > Best regards,
> > Tomasz Janeczko
> > amibroker.com
> > ----- Original Message -----
> > From: Herman
> > To: dingo
> > Cc: amibroker@xxxxxxxxxps.com
> > Sent: Friday, May 25, 2007 1:27 AM
> > Subject: Re: [amibroker] Nested Switch() statements
> >
> >
> > Thanks, I Thought it should work too. I probably made a mistake,
> its to long to post but I will post something similar (Cleaner!) on
> the UKB.
> >
> >
> >
> >
> > I'll have another look at it.
> >
> >
> >
> >
> > herman
> >
> >
> >
> >
> > Friday, May 25, 2007, 6:35:57 AM, you wrote:
> >
> >
> >
> >
> > >
> > I haven't tried nesting them but I would think it's
> permitted. Post your effort so you can get some eyeballs on it.
> >
> >
> >
> > d
> >
> >
> >
> >
> >
> >
> >
> >
> > ----------------------------------------------------------
------
> >
> > From: amibroker@xxxxxxxxxps.com
> [mailto:amibroker@xxxxxxxxxps.com] On Behalf Of Herman
> >
> > Sent: Thursday, May 24, 2007 6:33 PM
> >
> > To: AmiBroker User Group
> >
> > Subject: [amibroker] Nested Switch() statements
> >
> >
> >
> >
> > I am having some problems with nested Switch statements,
has
> any one tried nested Switch statements? Is this permitted?
> >
> >
> >
> >
> > Thanks,
> >
> > herman
> >
>

__._,_.___

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html





SPONSORED LINKS
Investment management software Investment property software Investment software
Investment tracking software Return on investment software

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___