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. General Programming
  3. C#
  4. [Message Deleted]

[Message Deleted]

Scheduled Pinned Locked Moved C#
16 Posts 10 Posters 0 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.
  • R R_L_H

    [Message Deleted]

    J Offline
    J Offline
    Judah Gabriel Himango
    wrote on last edited by
    #3

    Richard Hartness wrote:

    ase statements are terminated with the C# keyword break. Unde

    I guess you could have a boolean flag as part of the while loop, bool isBreakingFromDefault, and just set that flag to true when you break from default. When the while loop sees that flag as true, break from the while loop as well. FWIW, I think the switch construct is butt ugly and often confusing. I'd much rather see a few if/elses.

    Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

    C V 2 Replies Last reply
    0
    • R Rob Graham

      "exit while;" Ooops -VB.Net only...

      Last modified: 4mins after originally posted -- correction

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #4

      I could certainly be missing something but I thought this was for VB not C#.


      only two letters away from being an asset

      1 Reply Last reply
      0
      • R Rob Graham

        "exit while;" Ooops -VB.Net only...

        Last modified: 4mins after originally posted -- correction

        J Offline
        J Offline
        Judah Gabriel Himango
        wrote on last edited by
        #5

        :confused: There's an exit keyword in C#?

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

        1 Reply Last reply
        0
        • R Rob Graham

          "exit while;" Ooops -VB.Net only...

          Last modified: 4mins after originally posted -- correction

          O Offline
          O Offline
          Oleg A Lukin
          wrote on last edited by
          #6

          It's from C# language specification: When multiple switch, while, do, for, or foreach statements are nested within each other, a break statement applies only to the innermost statement. To transfer control across multiple nesting levels, a goto statement (§8.9.3) must be used. using System; class Test { static void Main(string[] args) { string[,] table = { {"Red", "Blue", "Green"}, {"Monday", "Wednesday", "Friday"} }; foreach (string str in args) { int row, colm; for (row = 0; row <= 1; ++row) for (colm = 0; colm <= 2; ++colm) if (str == table[row,colm]) goto done; Console.WriteLine("{0} not found", str); continue; done: Console.WriteLine("Found {0} at [{1}][{2}]", str, row, colm); } } }

          J 1 Reply Last reply
          0
          • O Oleg A Lukin

            It's from C# language specification: When multiple switch, while, do, for, or foreach statements are nested within each other, a break statement applies only to the innermost statement. To transfer control across multiple nesting levels, a goto statement (§8.9.3) must be used. using System; class Test { static void Main(string[] args) { string[,] table = { {"Red", "Blue", "Green"}, {"Monday", "Wednesday", "Friday"} }; foreach (string str in args) { int row, colm; for (row = 0; row <= 1; ++row) for (colm = 0; colm <= 2; ++colm) if (str == table[row,colm]) goto done; Console.WriteLine("{0} not found", str); continue; done: Console.WriteLine("Found {0} at [{1}][{2}]", str, row, colm); } } }

            J Offline
            J Offline
            Judah Gabriel Himango
            wrote on last edited by
            #7

            Ahhhh! Not the notorious goto! X|

            Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

            O R 2 Replies Last reply
            0
            • R R_L_H

              [Message Deleted]

              E Offline
              E Offline
              ednrgc
              wrote on last edited by
              #8

              Even though you already mentioned this, it's short, and pretty much the standard: bool bContinue = true; while( myOtherCriteria && bContinue) { case... ... ... otherwise: bContinue = false; }

              1 Reply Last reply
              0
              • R R_L_H

                [Message Deleted]

                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #9

                To be weirder, you can throw an exception...:):):)

                1 Reply Last reply
                0
                • J Judah Gabriel Himango

                  Ahhhh! Not the notorious goto! X|

                  Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                  O Offline
                  O Offline
                  Oleg A Lukin
                  wrote on last edited by
                  #10

                  Well, I don't much like goto myself but that's the way Microsoft specifications provide. The good thing is that at least all finally blocks are still processed so not much harm is done. Sometimes goto is far more comprehensive than additional boolean flags and checks in nested loops.

                  1 Reply Last reply
                  0
                  • J Judah Gabriel Himango

                    Richard Hartness wrote:

                    ase statements are terminated with the C# keyword break. Unde

                    I guess you could have a boolean flag as part of the while loop, bool isBreakingFromDefault, and just set that flag to true when you break from default. When the while loop sees that flag as true, break from the while loop as well. FWIW, I think the switch construct is butt ugly and often confusing. I'd much rather see a few if/elses.

                    Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #11

                    Judah Himango wrote:

                    FWIW, I think the switch construct is butt ugly and often confusing. I'd much rather see a few if/elses.

                    Wow - I think the reverse.  They are, of course, the same thing in the end.

                    Christian Graus - C++ MVP

                    1 Reply Last reply
                    0
                    • R R_L_H

                      [Message Deleted]

                      R Offline
                      R Offline
                      Ravi Bhavnani
                      wrote on last edited by
                      #12

                      Richard Hartness wrote:

                      C# seems to break down a little.

                      Actually, I don't think this has anything to do with C# per se. C and C++ work the same way. /ravi

                      My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

                      R 1 Reply Last reply
                      0
                      • J Judah Gabriel Himango

                        Ahhhh! Not the notorious goto! X|

                        Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                        R Offline
                        R Offline
                        Ravi Bhavnani
                        wrote on last edited by
                        #13

                        It's not notorious when used to branch to the end of a block. In fact, that's what break and return do. Djikstra's paper has to do with branching into a control block, there making program verification orders of magnitude more difficult. /ravi

                        My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

                        1 Reply Last reply
                        0
                        • R Ravi Bhavnani

                          Richard Hartness wrote:

                          C# seems to break down a little.

                          Actually, I don't think this has anything to do with C# per se. C and C++ work the same way. /ravi

                          My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

                          R Offline
                          R Offline
                          R_L_H
                          wrote on last edited by
                          #14

                          [Message Deleted]

                          R 1 Reply Last reply
                          0
                          • R R_L_H

                            [Message Deleted]

                            R Offline
                            R Offline
                            Ravi Bhavnani
                            wrote on last edited by
                            #15

                            Richard Hartness wrote:

                            awesome New Years resolution

                            Sadly, yet to be realized. :) /ravi

                            My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot0com

                            1 Reply Last reply
                            0
                            • J Judah Gabriel Himango

                              Richard Hartness wrote:

                              ase statements are terminated with the C# keyword break. Unde

                              I guess you could have a boolean flag as part of the while loop, bool isBreakingFromDefault, and just set that flag to true when you break from default. When the while loop sees that flag as true, break from the while loop as well. FWIW, I think the switch construct is butt ugly and often confusing. I'd much rather see a few if/elses.

                              Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                              V Offline
                              V Offline
                              V 0
                              wrote on last edited by
                              #16

                              Judah Himango wrote:

                              I think the switch construct is butt ugly and often confusing. I'd much rather see a few if/elses.

                              :wtf: the switch is excellent, but not really usable in every case, but so are if/elses. Just use the right tool for the job :).

                              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