Click here to Skip to main content
15,884,472 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Gotoless programming Pin
CDP180222-Feb-12 2:22
CDP180222-Feb-12 2:22 
GeneralRe: Gotoless programming PinPopular
Bull City Rambler23-Feb-12 15:21
Bull City Rambler23-Feb-12 15:21 
GeneralRe: Gotoless programming Pin
OriginalGriff23-Feb-12 21:23
mveOriginalGriff23-Feb-12 21:23 
GeneralRe: Gotoless programming Pin
SortaCore28-Feb-12 7:39
SortaCore28-Feb-12 7:39 
GeneralRe: Gotoless programming Pin
OriginalGriff28-Feb-12 8:07
mveOriginalGriff28-Feb-12 8:07 
GeneralRe: Gotoless programming PinPopular
archimboldo28-Feb-12 8:11
archimboldo28-Feb-12 8:11 
GeneralRe: Gotoless programming Pin
SortaCore28-Feb-12 8:42
SortaCore28-Feb-12 8:42 
GeneralRe: Gotoless programming Pin
Mark Kruger28-Feb-12 10:44
Mark Kruger28-Feb-12 10:44 
Good example exactly of not using goto at all,
it's easily converted to an if then else situation.
which increases readability if u would ask me.

C#
while(settext())
{
   // Command 1 (no parameters)
   if(!stricmp(text, "something"))
   {
      DoStuff();
 //     continue; // Skip command 2-3 & error check
   }

   // Command 2 (single parameter - text to match)
   else if(!strincmp(text, sizeof("other thing ")-1, "other thing "))
   {
      for(unsigned int i = 0; i < StringArray.size(); ++i)
      {
          if(!stricmp(text+sizeof("other thing ")-1, StringArray[i]))
          {
             StringArray.erase(i);
             break; // or use goto JumpHere?
          }
      }

      // Did not find? You have to use a variable to check
      ReportError("parameter not found");
 //     continue; // Skip command 3 & error check
   }

   // Command 3 (not set up)
   else if(!stricmp(text, "asparagus"))
   {
 //      continue; // Skip error check
   }
   else

   {
      // Error check
      ReportError("command not found");
 //     JumpHere:
 //      continue; // Labels must have a statement
   }
}

GeneralRe: Gotoless programming Pin
SortaCore28-Feb-12 17:34
SortaCore28-Feb-12 17:34 
GeneralRe: Gotoless programming Pin
Mark Kruger28-Feb-12 21:16
Mark Kruger28-Feb-12 21:16 
GeneralRe: Gotoless programming Pin
SortaCore29-Feb-12 6:51
SortaCore29-Feb-12 6:51 
GeneralRe: Gotoless programming Pin
Mark Kruger29-Feb-12 8:31
Mark Kruger29-Feb-12 8:31 
GeneralRe: Gotoless programming Pin
Ahmedn128-Feb-12 8:41
Ahmedn128-Feb-12 8:41 
GeneralRe: Gotoless programming Pin
BobJanova28-Feb-12 22:33
BobJanova28-Feb-12 22:33 
GeneralRe: Gotoless programming Pin
DragonHeart33528-Feb-12 1:13
DragonHeart33528-Feb-12 1:13 
GeneralRe: Gotoless programming Pin
scott_m557428-Feb-12 3:25
scott_m557428-Feb-12 3:25 
GeneralRe: Gotoless programming Pin
Mike Winiberg27-Feb-12 21:14
professionalMike Winiberg27-Feb-12 21:14 
GeneralRe: Gotoless programming Pin
englebart28-Feb-12 2:06
professionalenglebart28-Feb-12 2:06 
GeneralRe: Gotoless programming Pin
code_junkie28-Feb-12 2:42
code_junkie28-Feb-12 2:42 
GeneralRe: Gotoless programming Pin
Renzo Ciafardone28-Feb-12 3:53
Renzo Ciafardone28-Feb-12 3:53 
GeneralRe: Gotoless programming Pin
Marbry Hardin28-Feb-12 4:28
Marbry Hardin28-Feb-12 4:28 
GeneralRe: Gotoless programming Pin
code_junkie28-Feb-12 4:52
code_junkie28-Feb-12 4:52 
GeneralRe: Gotoless programming Pin
BobJanova28-Feb-12 5:11
BobJanova28-Feb-12 5:11 
GeneralRe: Gotoless programming Pin
Rachel Mant2-Jun-12 14:49
Rachel Mant2-Jun-12 14:49 
GeneralRe: Gotoless programming Pin
Member 834855428-Feb-12 5:44
Member 834855428-Feb-12 5:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.