Thanks. First of all, I'll let Bill Gates know. Visual Foxpro is as you know a 
MS product. But secondly what the DO CASE does in Foxpro is exactly what I want 
it to do. And yes that is a different and more structured way of IF THENs. 
Anyway it's good to know that also on this topic the world is full with 
different opinions and AFL is following the other way to Rome ...

Regards, Ton.

  ----- Original Message ----- 
  From: Dennis Brown 
  To: [email protected] 
  Sent: Saturday, May 26, 2007 10:48 PM
  Subject: Re: [amibroker] Re: Nested Switch() statements


  Ton,



  Well that is a really poor implementation of Case, giving you no more utility 
than a bunch of IF THENs.  The way that Tomasz has done it is the right way.  
Fall through IS the reason to have the Switch -Case -Break  -Default construct. 
 Forget about the Foxpro ideas below.


  Dennis


  On May 26, 2007, at 2:46 PM, Ton Sieverding wrote:


    Thanks Nigel. I have a serious problem with the following remark :

    > If you leave out the break statements, and 
    > expression==constant_expression1 you will execute statement1 (what you 
    > wanted) AND ALSO statement2 AND ALSO statement3 AND ALSO ... statementN 
    > AND ALSO statement_default.

    So what you are telling me is that after having executed statement1, SWITCH 
will execute all the other case statements too. Because there is no break. I am 
using the SWITCH ( Visual Foxpro called DO CASE ) statement and never have seen 
this. Once one of the cases it true, the corresponding command will be executed 
and you're leaving the SWITCH structure. There are no breaks needed to exit 
SWITCH. Is this different in AFL ? Please reed underneath mentioned help text 
from MS Visual FoxPro :

    CASE lExpression1 Commands ...   When the first true (.T.) CASE expression 
is encountered, the set of commands following it is executed. Execution of the 
set of commands continues until the next CASE or ENDCASE is reached. Execution 
then resumes with the first command following ENDCASE.

    If a CASE expression is false (.F.), the set of commands following it up to 
the next CASE clause is ignored.

    Only one set of commands is executed. These are the first commands whose 
CASE expression evaluates to true (.T.). Any succeeding true (.T.) CASE 
expressions are ignored.

    Of course what I should and will do is test what the AFL SWITCH really does 
...

    Regards, Ton.


    ----- Original Message -----
    From: "Nigel Rowe" <[EMAIL PROTECTED]>
    To: <[email protected]>
    Sent: Friday, May 25, 2007 12:12 PM
    Subject: Re: [amibroker] Re: Nested Switch() statements


    > On Fri, 25 May 2007, Ton Sieverding wrote:
    > > 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-expression2 : statement;
    > >     ...
    > >     case constant-expressionN : statement;
    > >
    > >     default : statement;
    > >
    > > }
    > >
    > >
    > > Ton.
    > 
    > The 'standard' error when using a switch statement in 'C' and presumably 
    > AFL, is forgetting to put 'break;' statements in.
    > 
    > To paraphrase your example (above) so it looks like this:-
    > 
    > switch ( expression )
    > {
    >     case constant-expression1 : statement1;
    >     case constant-expression2 : statement2;
    >     ...
    >     case constant-expressionN : statementN;
    >     default : statement_default;
    > }
    > 
    > If you leave out the break statements, and 
    > expression==constant_expression1 you will execute statement1 (what you 
    > wanted) AND ALSO statement2 AND ALSO statement3 AND ALSO ... statementN 
    > AND ALSO statement_default.
    > 
    > It's sometimes called the 'fall-through' bug.  It's easy to miss, can be 
    > a right pain!
    > 
    > 
    > -- 
    > Nigel Rowe
    > rho \N{COMMERCIAL AT} swiftdsl \N{FULL STOP} com \N{FULL STOP} au
    > 
    > 
    > 
    > 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
    >  
    > Yahoo! Groups Links
    > 
    > 
    > 



   

Reply via email to