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 / C++ / MFC
  4. rewrite programs without gotos and breaks

rewrite programs without gotos and breaks

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 3 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.
  • P Offline
    P Offline
    phokojoe
    wrote on last edited by
    #1

    i have this code guys: j = -3; for (i=0;i<3;i++) { switch (j+2) { case 3: case 2: j--; break; case 0: j += 2; break; default: j=0; } if (j>0) break; j = 3-i; } i want to write this without the breaks and goto how can i do it gurus? :sigh:

    phokojoe

    S S 2 Replies Last reply
    0
    • P phokojoe

      i have this code guys: j = -3; for (i=0;i<3;i++) { switch (j+2) { case 3: case 2: j--; break; case 0: j += 2; break; default: j=0; } if (j>0) break; j = 3-i; } i want to write this without the breaks and goto how can i do it gurus? :sigh:

      phokojoe

      S Offline
      S Offline
      Sarath C
      wrote on last edited by
      #2

      int j = 1; Remove everything else. It's better to do your homework yourself.

      -Sarath. "Great hopes make everything great possible" - Benjamin Franklin

      My blog - Sharing My Thoughts, An Article - Understanding Statepattern

      1 Reply Last reply
      0
      • P phokojoe

        i have this code guys: j = -3; for (i=0;i<3;i++) { switch (j+2) { case 3: case 2: j--; break; case 0: j += 2; break; default: j=0; } if (j>0) break; j = 3-i; } i want to write this without the breaks and goto how can i do it gurus? :sigh:

        phokojoe

        S Offline
        S Offline
        Subrat 4708266
        wrote on last edited by
        #3

        j = -3; int k = 0; for (i=0; (i < 3) && (j > 0); i++) { k = j + 2; if((3 == k) || (2 == k)) { j--; } else if (0 == k) { j += 2; } else { j = 0; } if(j <= 0) { j = 3 - i; } }

        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