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. for those of you purists that don't like break, continue and goto

for those of you purists that don't like break, continue and goto

Scheduled Pinned Locked Moved The Lounge
question
65 Posts 21 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.
  • H honey the codewitch

    why do this?

    for(int i = 0;i
    instead of

    for(int i = 0;i

    hengh?? why you still use break?

    :laugh:

    When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

    A Offline
    A Offline
    AnotherKen
    wrote on last edited by
    #61

    only use Goto if you like spaghetti code ;)

    H 1 Reply Last reply
    0
    • A AnotherKen

      only use Goto if you like spaghetti code ;)

      H Offline
      H Offline
      honey the codewitch
      wrote on last edited by
      #62

      i use gotos for generated state machine code so the code will look exactly like the graphs generated by graphviz. it makes the code more understandable. like this snippet, implementing q1 of the graph:

      q1:
      if((pc.Current>='0'&& pc.Current<='9')||
      (pc.Current>='A'&& pc.Current<='Z')||
      (pc.Current=='_')||
      (pc.Current>='a'&& pc.Current<='z')) {
      sb.Append((char)pc.Current);
      pc.Advance();
      goto q1;
      }
      return new System.Collections.Generic.KeyValuePair("id",sb.ToString());

      from (A Regular Expression Engine in C#[^]) there's supposed to be a picture at the link but it's no longer showing up for me. maybe it will for you. in any case, there's a time and a place for everything.

      When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

      A 1 Reply Last reply
      0
      • H honey the codewitch

        i use gotos for generated state machine code so the code will look exactly like the graphs generated by graphviz. it makes the code more understandable. like this snippet, implementing q1 of the graph:

        q1:
        if((pc.Current>='0'&& pc.Current<='9')||
        (pc.Current>='A'&& pc.Current<='Z')||
        (pc.Current=='_')||
        (pc.Current>='a'&& pc.Current<='z')) {
        sb.Append((char)pc.Current);
        pc.Advance();
        goto q1;
        }
        return new System.Collections.Generic.KeyValuePair("id",sb.ToString());

        from (A Regular Expression Engine in C#[^]) there's supposed to be a picture at the link but it's no longer showing up for me. maybe it will for you. in any case, there's a time and a place for everything.

        When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

        A Offline
        A Offline
        AnotherKen
        wrote on last edited by
        #63

        If you can keep it that ordered then that is good. The problem with the convenience of goto is that it tends to end up being over-used and that is what leads to problems.

        H 1 Reply Last reply
        0
        • A AnotherKen

          If you can keep it that ordered then that is good. The problem with the convenience of goto is that it tends to end up being over-used and that is what leads to problems.

          H Offline
          H Offline
          honey the codewitch
          wrote on last edited by
          #64

          yeah, i use gotos pretty much in generated code. in this case, it just happened to make the code clearer, but state machines are kind of their own animal. It's really hard to implement one using "proper" looping techniques. At best you have a while(true) loop with a giant switch case in it. =(

          When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

          1 Reply Last reply
          0
          • H honey the codewitch

            why do this?

            for(int i = 0;i
            instead of

            for(int i = 0;i

            hengh?? why you still use break?

            :laugh:

            When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

            Z Offline
            Z Offline
            zezba9000
            wrote on last edited by
            #65

            Define purist? Because using C the way it was designed to be used in more pure.

            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