Click here to Skip to main content
15,885,914 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 PinPopular
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 
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 
If u want speed, i would const the size of for your fixed string,
would safe u getting it's length each time u go for another loop in the while.
The continues u fire are at end of each if slice, and in an if else construction
it would jump out to bottom anyways, so in this case i think continue actually will be equally fast at best and else even slower.

C#
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?
    }
}


I normally do different, a bit slower i assume but clear

C#
//somewhere outside the while
const int Sizer = sizeof("other thing ")-1;
//
 
int WalkTo = StringArray.size() - 1;

if (WalkTo >= 0)
{
    const char* Check = text + Sizer;
    int i = -1;
    int Found = 0;

    do
    {
       i++;
       if (!stricmp(Check, StringArray[i]))
       {
           StringArray.erase(i);
           Found = 1;
       }
    } while (!Found && (i < WalkTo));
}


modified 29-Feb-12 3:31am.

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 
GeneralRe: Gotoless programming Pin
cpkilekofp28-Feb-12 5:53
cpkilekofp28-Feb-12 5:53 
GeneralRe: Gotoless programming Pin
Member 316697428-Feb-12 3:14
Member 316697428-Feb-12 3:14 

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.