Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Breaks

Breaks

Scheduled Pinned Locked Moved The Lounge
c++question
40 Posts 22 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Eytukan

    Do you think the "break;" [C++] command is really needed at the end of every case statement? I've never been in a situation where I'd want the control to pass on to the next case after satisfying a particular case. You know I missed to put a "break;" and it resulted in a big chaos :doh:.


    Dario: How is "directory" in French? (I mean a file system directory). John Simmons: "zee file holdaire thingie"

    M Offline
    M Offline
    Member 96
    wrote on last edited by
    #30

    I've used fallthrough many times over the years so yes I'd say it's required.

    1 Reply Last reply
    0
    • E Eytukan

      Do you think the "break;" [C++] command is really needed at the end of every case statement? I've never been in a situation where I'd want the control to pass on to the next case after satisfying a particular case. You know I missed to put a "break;" and it resulted in a big chaos :doh:.


      Dario: How is "directory" in French? (I mean a file system directory). John Simmons: "zee file holdaire thingie"

      J Offline
      J Offline
      Joe Woodbury
      wrote on last edited by
      #31

      I have used fall throughs, though I've long felt the proper implementation would be that a new case statement implies break and to fall through you write fallthrough;. (I've also wanted the equivalent of "reswitch"--that is; go back and reevaluate the expression again.)

      Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

      E 2 Replies Last reply
      0
      • E Eytukan

        Do you think the "break;" [C++] command is really needed at the end of every case statement? I've never been in a situation where I'd want the control to pass on to the next case after satisfying a particular case. You know I missed to put a "break;" and it resulted in a big chaos :doh:.


        Dario: How is "directory" in French? (I mean a file system directory). John Simmons: "zee file holdaire thingie"

        H Offline
        H Offline
        Hans Dietrich
        wrote on last edited by
        #32

        PC-Lint will catch missing break statements, and a lot of other common coding oversights.

        E 1 Reply Last reply
        0
        • M Michael Dunn

          I've probably coded a fall-through like that maybe twice in my life. Not counting those times where I goofed and forgot the break. ;) (That shows what I think is a design mistake in C - the default behavior should be no fall-through between cases, since that's what programmers will want the vast majority of the time. Oh well.) I was just looking up the C# spec and C# requires break statements even though the behavior is no fall-through. Bwa? :confused:

          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #33

          Not only that but a fall-though is still supported but requires the use of the goto statement. I would have preferred an explicit “fall-through” keyword.

          Steve

          1 Reply Last reply
          0
          • J Joe Woodbury

            I have used fall throughs, though I've long felt the proper implementation would be that a new case statement implies break and to fall through you write fallthrough;. (I've also wanted the equivalent of "reswitch"--that is; go back and reevaluate the expression again.)

            Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

            E Offline
            E Offline
            Eytukan
            wrote on last edited by
            #34

            Very good idea.


            Dario: How is "directory" in French? (I mean a file system directory). John Simmons: "zee file holdaire thingie"

            1 Reply Last reply
            0
            • H Hans Dietrich

              PC-Lint will catch missing break statements, and a lot of other common coding oversights.

              E Offline
              E Offline
              Eytukan
              wrote on last edited by
              #35

              Thanks. It will be really required if we have switch-case blocks that contains 1000s of lines. will suggest that to my boss.


              Dario: How is "directory" in French? (I mean a file system directory). John Simmons: "zee file holdaire thingie"

              1 Reply Last reply
              0
              • T Todd Smith

                what about:switch (something) { case A: case B: case C: DoSomething(); break; case D: case E: case F: DoSomethingElse(); break; .... }

                Todd Smith

                E Offline
                E Offline
                Eytukan
                wrote on last edited by
                #36

                You mean, if it's case "A", it should perform A,B & C. if it's case "C", it directly comes to "C". Got it. I get the picture now!. :jig: thanks :beer:. It has it's use but as joe said above , it will really nice if we have something called fallthrough to explicitly mean it.


                Dario: How is "directory" in French? (I mean a file system directory). John Simmons: "zee file holdaire thingie"

                1 Reply Last reply
                0
                • J Joe Woodbury

                  I have used fall throughs, though I've long felt the proper implementation would be that a new case statement implies break and to fall through you write fallthrough;. (I've also wanted the equivalent of "reswitch"--that is; go back and reevaluate the expression again.)

                  Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

                  E Offline
                  E Offline
                  Eytukan
                  wrote on last edited by
                  #37

                  http://www.codeproject.com/lounge.asp?msg=1879599#xx1879599xx[^]


                  Dario: How is "directory" in French? (I mean a file system directory). John Simmons: "zee file holdaire thingie"

                  1 Reply Last reply
                  0
                  • V Vikram A Punathambekar

                    VuNic wrote:

                    Do you think the "break;" [C++] command is really needed at the end of every case statement?

                    No. I think the default behavior is wrong here.

                    VuNic wrote:

                    I've never been in a situation where I'd want the control to pass on to the next case after satisfying a particular case.

                    I have. [edit]I make sure it's commented prominently.[/edit]

                    Cheers, Vikram.


                    "...we are disempowered to cultivate in their communities an inclination to assimilate to our culture." - Stan Shannon.

                    E Offline
                    E Offline
                    Eytukan
                    wrote on last edited by
                    #38

                    Someone didn't like you editing your message? :wtf:. Never mind, balanced ;)


                    Dario: How is "directory" in French? (I mean a file system directory). John Simmons: "zee file holdaire thingie"

                    1 Reply Last reply
                    0
                    • C Christian Graus

                      Yep, they enforced break because otherwise the code is hard to read, and then they encouraged goto. Brilliant.

                      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                      E Offline
                      E Offline
                      Eytukan
                      wrote on last edited by
                      #39

                      Christian Graus wrote:

                      Yep, they enforced break because otherwise the code is hard to read, and then they encouraged goto. Brilliant.

                      :laugh:


                      Dario: How is "directory" in French? (I mean a file system directory). John Simmons: "zee file holdaire thingie"

                      1 Reply Last reply
                      0
                      • E Eytukan

                        Do you think the "break;" [C++] command is really needed at the end of every case statement? I've never been in a situation where I'd want the control to pass on to the next case after satisfying a particular case. You know I missed to put a "break;" and it resulted in a big chaos :doh:.


                        Dario: How is "directory" in French? (I mean a file system directory). John Simmons: "zee file holdaire thingie"

                        S Offline
                        S Offline
                        Smith
                        wrote on last edited by
                        #40

                        Wow yet another case with the switch case :-D

                        :beer:

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups