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. visual C# 2005 exiting

visual C# 2005 exiting

Scheduled Pinned Locked Moved C#
csharphelptutorial
56 Posts 9 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.
  • X xxmikexx

    kinda i am using visual C# not the console one the one were you can place buttons and stuff they are similiar but different i cant test this till i am at school tomorrow when it returns where does it go to? this seems to help tho thanks alot if it just leaves the whole if statement that would be great

    E Offline
    E Offline
    engsrini
    wrote on last edited by
    #32

    the code which i posted can work in both console and windows.. dont confuse with Debug.Writeline satement, it is just used to print in Output Window. ie. private void button1_Click(object sender, EventArgs e) { int x = 5; if (x == 5) { Debug.WriteLine("more code to runs here1"); Debug.WriteLine("more code to runs here2"); if(done) return; // This will exit the funtion button1_Click else { Debug.WriteLine("more code to runs here3"); Debug.WriteLine("more code to runs here4"); Debug.WriteLine("more code to runs here5"); } } Debug.WriteLine("more code to runs here6"); Debug.WriteLine("more code to runs here7"); Debug.WriteLine("more code to runs here8"); } the return statement will exit from the funtion button1_Click. Srini

    X 1 Reply Last reply
    0
    • L led mike

      Ennis Ray Lynch, Jr. wrote:

      Return is not allowed inside of methods more than once and should not be used by any method that does not have a functional result. Doing so is a poor programming practice that violates the one-in, one-out principle.

      Yeah, that's what I thought also until I read Implementation Patterns by Kent Beck: Back in the old days of programming, a commandment was issued: each routine shall have a single entry and a single exit. This was to prevent the confusion possible when jumping into and out of many locations in the same routine. It made good sense when applied to FORTRAN or assembly language programs written with lots of global data where even understanding which statements were executed was hard work. In Java, with small methods and mostly local data, it is needlessly conservative. However, this bit of programming folklore, thoughtlessly obeyed, prevents the use of guard clauses. Guard clauses are particularly useful when there are multiple conditions: [Code example snipped of nested if statements with a single return] Nested conditionals breed defects. The guard clause version of the same code notes the prerequisites to processing a request without complex control structures: [Code example snipped of flat if statements each with a return ] Keep in mind there is more context to his segment on the Guard Clause. If you are interested I highly recommend the book.

      All truth passes through three stages. First, it is ridiculed. Second, it is violently opposed. Third, it is accepted as being self-evident.

      Arthur Schopenhauer - German philosopher (1788 - 1860)

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #33

      Unfortunately, the nature of business software development causes me to recommend against this. Using structured exists simplifies debugging and serves as a preventative measure from a junior programmer going haywire with a 10 page method. While I can say a deeply nested conditional does breed defects the case is made to follow Fowler on this one and refactor into more simpler methods.

      Need a C# Consultant? I'm available.
      Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

      L 1 Reply Last reply
      0
      • E engsrini

        the code which i posted can work in both console and windows.. dont confuse with Debug.Writeline satement, it is just used to print in Output Window. ie. private void button1_Click(object sender, EventArgs e) { int x = 5; if (x == 5) { Debug.WriteLine("more code to runs here1"); Debug.WriteLine("more code to runs here2"); if(done) return; // This will exit the funtion button1_Click else { Debug.WriteLine("more code to runs here3"); Debug.WriteLine("more code to runs here4"); Debug.WriteLine("more code to runs here5"); } } Debug.WriteLine("more code to runs here6"); Debug.WriteLine("more code to runs here7"); Debug.WriteLine("more code to runs here8"); } the return statement will exit from the funtion button1_Click. Srini

        X Offline
        X Offline
        xxmikexx
        wrote on last edited by
        #34

        thank you so much that was exactly what i needed it should worl and i will tell you tomorrow if it does

        1 Reply Last reply
        0
        • X xxmikexx

          wow just wow how am i supposed to know that everything at school s blocked i have been programming for 3 days sorry i am not some master programmer in the 3 days since i have started everything i have learned is from code snippets... just please please do me a favor and dont comment on this thread if you are not going to help thats fine dont insult me... better yet just go die

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

          xxmikexx wrote:

          better yet just go die

          Well eventually I will, immortality would get boring after the first millennium anyway.


          only two letters away from being an asset

          X 1 Reply Last reply
          0
          • N Not Active

            Ennis Ray Lynch, Jr. wrote:

            Return is not allowed

            Not allowed, or not recommended? Two different things. I don't know of any language that places a restriction on the number of return statements that can be used in a block of code. However, yes, good design principles dictate that you should have as few exit points as possible. The original question only asked what the equivalent of VB's exit sub was, not how it should be used. Both Mike and I answered that direct question. Saying "Don't listen to anyone else" is a bit over the top.


            only two letters away from being an asset

            E Offline
            E Offline
            Ennis Ray Lynch Jr
            wrote on last edited by
            #36

            Anyone with the experience and judgment to disregard my statement would do so. Telling a novice not to do it is perfectly inline. A lot of the advice I give is structured to introductory programmers as more experienced developers have the experience to know when it is hogwash. By biasing my response towards less experienced developers I increase the value of the statements. I will repeat my statement with the inferred subtext: "Return is not allowed unless you have the experience and judgment to properly identify cases for its use and understand the consequences both positive and negative"

            Need a C# Consultant? I'm available.
            Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

            1 Reply Last reply
            0
            • X xxmikexx

              we dont have an "admissions office" also in high school you dont have a major...

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

              xxmikexx wrote:

              high school

              Well that explains a lot. Now, go do your homework and leave this to the adults.


              only two letters away from being an asset

              X 1 Reply Last reply
              0
              • N Not Active

                xxmikexx wrote:

                better yet just go die

                Well eventually I will, immortality would get boring after the first millennium anyway.


                only two letters away from being an asset

                X Offline
                X Offline
                xxmikexx
                wrote on last edited by
                #38

                seem to disregard the message i sent you

                1 Reply Last reply
                0
                • N Not Active

                  xxmikexx wrote:

                  high school

                  Well that explains a lot. Now, go do your homework and leave this to the adults.


                  only two letters away from being an asset

                  X Offline
                  X Offline
                  xxmikexx
                  wrote on last edited by
                  #39

                  http://mansoftdev.com/Resume/Mark%20Nischalke.doc[^] i believe i found that guys problem... he seems to be upset most likely because he has no people skills and by the looks of it cant seem to hold down a job... maybe just me but maybe no one else seems to like him, idk just throwing that out there

                  N 1 Reply Last reply
                  0
                  • X xxmikexx

                    thanks for that it is really hard to explain what i mean tho, i know about that but since it is a timer once it is executed it will set off all of the others that is what i want it to do but i want to go through one if statement each time the timer is used. i am making a program with a group of 16 buttons and when they click one it changes the colors of those around it and i want to send out a wave effect so the only practical way i could think of was finding something similiar to that break thing other wise all of them will go off i just dont really know how to explain what i need thanks for the help tho

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #40

                    It sounds like you need to rethink your logic a bit. The requirements you just spelled out shouldn't require such a complex if statement.

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                         2006, 2007

                    X 1 Reply Last reply
                    0
                    • X xxmikexx

                      http://mansoftdev.com/Resume/Mark%20Nischalke.doc[^] i believe i found that guys problem... he seems to be upset most likely because he has no people skills and by the looks of it cant seem to hold down a job... maybe just me but maybe no one else seems to like him, idk just throwing that out there

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

                      Wow, you found my resume online. I'm impressed and awed by your skills. I see that not only are you an experienced developer, but also a psychologist. So tell me Dr., why do I hate my mother? Speaking of mothers, I think yours is calling. It's past your bedtime anyway, so run along little one.


                      only two letters away from being an asset

                      X R 2 Replies Last reply
                      0
                      • D Dave Kreskowiak

                        It sounds like you need to rethink your logic a bit. The requirements you just spelled out shouldn't require such a complex if statement.

                        A guide to posting questions on CodeProject[^]
                        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                             2006, 2007

                        X Offline
                        X Offline
                        xxmikexx
                        wrote on last edited by
                        #42

                        o really lol i guess there would be a better way

                        1 Reply Last reply
                        0
                        • N Not Active

                          Wow, you found my resume online. I'm impressed and awed by your skills. I see that not only are you an experienced developer, but also a psychologist. So tell me Dr., why do I hate my mother? Speaking of mothers, I think yours is calling. It's past your bedtime anyway, so run along little one.


                          only two letters away from being an asset

                          X Offline
                          X Offline
                          xxmikexx
                          wrote on last edited by
                          #43

                          haha for a "big mature adult" which for whatever you seem to think you are, you behave much more imaturely than my little sister, i cant explain y you hate your mother but probably because you are a failure to what you truly want to be have average skills and think that towering over younger people and imposing your measly imaginitive power deep down inside this makes you feel better and people liek you need to grow up and are just dispicable.

                          1 Reply Last reply
                          0
                          • N Not Active

                            Wow, you found my resume online. I'm impressed and awed by your skills. I see that not only are you an experienced developer, but also a psychologist. So tell me Dr., why do I hate my mother? Speaking of mothers, I think yours is calling. It's past your bedtime anyway, so run along little one.


                            only two letters away from being an asset

                            R Offline
                            R Offline
                            rockNroll
                            wrote on last edited by
                            #44

                            Looking at your experience, i am sure you are definitely over 30 yrs of age. And mike is a kid in front of you...Common man..chill out now. It's not making you any better. Be nice with others and they ll be nice with you. ***Simple golden rule*** :)

                            X N M 3 Replies Last reply
                            0
                            • R rockNroll

                              Looking at your experience, i am sure you are definitely over 30 yrs of age. And mike is a kid in front of you...Common man..chill out now. It's not making you any better. Be nice with others and they ll be nice with you. ***Simple golden rule*** :)

                              X Offline
                              X Offline
                              xxmikexx
                              wrote on last edited by
                              #45

                              haha ya i agree i probably should of just ignored everthing he said but it is funny since he is getting mad over nothing i dont care lol

                              1 Reply Last reply
                              0
                              • R rockNroll

                                Looking at your experience, i am sure you are definitely over 30 yrs of age. And mike is a kid in front of you...Common man..chill out now. It's not making you any better. Be nice with others and they ll be nice with you. ***Simple golden rule*** :)

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

                                Oh come on, it sure is fun and certainly made the day go by :laugh:


                                only two letters away from being an asset

                                X 1 Reply Last reply
                                0
                                • N Not Active

                                  Oh come on, it sure is fun and certainly made the day go by :laugh:


                                  only two letters away from being an asset

                                  X Offline
                                  X Offline
                                  xxmikexx
                                  wrote on last edited by
                                  #47

                                  haha he is trying to act like he doesnt care well he is probably about ready to run home to mommy to lick his wounds

                                  R 1 Reply Last reply
                                  0
                                  • X xxmikexx

                                    haha he is trying to act like he doesnt care well he is probably about ready to run home to mommy to lick his wounds

                                    R Offline
                                    R Offline
                                    rockNroll
                                    wrote on last edited by
                                    #48

                                    Anyway mike you need to stop replying back now. Finish it now. He is quite elder to you..so you can take a initiative to be good with him by not stretching this more... All the best.

                                    X 1 Reply Last reply
                                    0
                                    • R rockNroll

                                      Anyway mike you need to stop replying back now. Finish it now. He is quite elder to you..so you can take a initiative to be good with him by not stretching this more... All the best.

                                      X Offline
                                      X Offline
                                      xxmikexx
                                      wrote on last edited by
                                      #49

                                      ya you are right thank you all for helping me with my problem

                                      1 Reply Last reply
                                      0
                                      • R rockNroll

                                        Looking at your experience, i am sure you are definitely over 30 yrs of age. And mike is a kid in front of you...Common man..chill out now. It's not making you any better. Be nice with others and they ll be nice with you. ***Simple golden rule*** :)

                                        M Offline
                                        M Offline
                                        MarkB777
                                        wrote on last edited by
                                        #50

                                        I think its funny :)

                                        1 Reply Last reply
                                        0
                                        • E Ennis Ray Lynch Jr

                                          Unfortunately, the nature of business software development causes me to recommend against this. Using structured exists simplifies debugging and serves as a preventative measure from a junior programmer going haywire with a 10 page method. While I can say a deeply nested conditional does breed defects the case is made to follow Fowler on this one and refactor into more simpler methods.

                                          Need a C# Consultant? I'm available.
                                          Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

                                          L Offline
                                          L Offline
                                          led mike
                                          wrote on last edited by
                                          #51

                                          Ennis Ray Lynch, Jr. wrote:

                                          Unfortunately, the nature of business software development

                                          That book is specifically directed at business software. Again, I highly recommend it. There is no way I am going believe my perspective is more reliable than someone like Kent Beck. Following the advice of experts in the industry like Beck is what I have always done, I am not about to change that now.

                                          Ennis Ray Lynch, Jr. wrote:

                                          the case is made to follow Fowler on this one

                                          This is from the first page of the book: "Many people don't realize how readable code can be and how valuable that readability is. Kent has taught me so much, I'm glad this book gives everyone the chance to learn from him." - Martin Fowler, chief scientist, ThoughtWorks There are six people endorsing the book on that first page, one of them besides Fowler is Erich Gamma.

                                          Ennis Ray Lynch, Jr. wrote:

                                          and refactor into more simpler methods.

                                          The small excerpt I posted does not provide his entire discussion on the subject of Guard Clauses nor the context for the entire book nor the books discussion of refactoring into smaller methods. Perhaps before concluding his reasoning is wrong, you might want to read the book so you can know what his reasoning is before you decide to dismiss it.

                                          led mike

                                          E 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