Loading ...
Sorry, an error occurred while loading the content.

Expected a 'break' statement before 'case'

Expand Messages
  • Fred Lorrain
    Hello, I know that break is recommended before a case but it s not mandatory. In the following example there is nothing wrong, right? switch (this.layout) {
    Message 1 of 3 , Aug 20, 2008
    View Source
    • 0 Attachment
      Hello,

      I know that break is recommended before a case but it's not mandatory.
      In the following example there is nothing wrong, right?

      switch (this.layout) {
      case 'calendarmonth2':
      ...
      this.generateMonth = this.generateMonth_finonline;
      case 'calendarmonth':
      this.drawMonthTabs();
      break;
      case 'calendarteaser':
      ...
      break;
      default:
      ...
      }

      Omitting the break before calendarmonth is done on purpose.
      Isn't it the right way to do it?

      Maybe the word Warning should be used instead of problem.

      Warning at line 732 character 66: Expected a 'break' statement before
      'case'.

      Instead of

      Problem at line 732 character 66: Expected a 'break' statement before
      'case'.


      [Non-text portions of this message have been removed]
    • Douglas Crockford
      ... I thought you were supposed to be the too strict, too maniac guy. See http://yuiblog.com/blog/2007/04/25/id-rather-switch-than-fight/
      Message 2 of 3 , Aug 20, 2008
      View Source
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "Fred Lorrain" <yahoo@...> wrote:
        > I know that break is recommended before a case but it's not mandatory.
        > In the following example there is nothing wrong, right?
        >
        > switch (this.layout) {
        > case 'calendarmonth2':
        > ...
        > this.generateMonth = this.generateMonth_finonline;
        > case 'calendarmonth':
        > this.drawMonthTabs();
        > break;
        > case 'calendarteaser':
        > ...
        > break;
        > default:
        > ...
        > }
        >
        > Omitting the break before calendarmonth is done on purpose.
        > Isn't it the right way to do it?
        >
        > Maybe the word Warning should be used instead of problem.
        >
        > Warning at line 732 character 66: Expected a 'break' statement before
        > 'case'.
        >
        > Instead of
        >
        > Problem at line 732 character 66: Expected a 'break' statement before
        > 'case'.

        I thought you were supposed to be the too strict, too maniac guy.

        See http://yuiblog.com/blog/2007/04/25/id-rather-switch-than-fight/
      • Fred Lorrain
        ... Thank you very much for the link. No I understand and accept this rule :D This rule has now a clear explanation in the messages of JSLint discussion group
        Message 3 of 3 , Aug 20, 2008
        View Source
        • 0 Attachment
          --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...>
          wrote:
          >
          > --- In jslint_com@yahoogroups.com, "Fred Lorrain" <yahoo@> wrote:
          > > I know that break is recommended before a case but it's not mandatory.
          > > In the following example there is nothing wrong, right?
          > >
          > > switch (this.layout) {
          > > case 'calendarmonth2':
          > > ...
          > > this.generateMonth = this.generateMonth_finonline;
          > > case 'calendarmonth':
          > > this.drawMonthTabs();
          > > break;
          > > case 'calendarteaser':
          > > ...
          > > break;
          > > default:
          > > ...
          > > }
          > >
          > > Omitting the break before calendarmonth is done on purpose.
          > > Isn't it the right way to do it?
          > >
          > > Maybe the word Warning should be used instead of problem.
          > >
          > > Warning at line 732 character 66: Expected a 'break' statement before
          > > 'case'.
          > >
          > > Instead of
          > >
          > > Problem at line 732 character 66: Expected a 'break' statement before
          > > 'case'.
          >
          > I thought you were supposed to be the too strict, too maniac guy.
          >
          > See http://yuiblog.com/blog/2007/04/25/id-rather-switch-than-fight/
          >

          Thank you very much for the link.
          No I understand and accept this rule :D

          This rule has now a clear explanation in the messages of JSLint
          discussion group :D

          I hope all my messages are not flooding the discussion group.
          My intention is to provide feedback on most of the nice rules applied
          by JSLint.
        Your message has been successfully submitted and would be delivered to recipients shortly.