Click here to Skip to main content
15,887,821 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: Which code you suggest? Pin
Stefan_Lang29-Jul-13 21:26
Stefan_Lang29-Jul-13 21:26 
GeneralRe: Which code you suggest? Pin
BobJanova29-Jul-13 0:23
BobJanova29-Jul-13 0:23 
GeneralRe: Which code you suggest? Pin
Stefan_Lang29-Jul-13 2:44
Stefan_Lang29-Jul-13 2:44 
AnswerRe: Which code you suggest? Pin
BotReject26-Jul-13 0:47
BotReject26-Jul-13 0:47 
AnswerRe: Which code you suggest? Pin
Kenworth7126-Jul-13 1:04
professionalKenworth7126-Jul-13 1:04 
AnswerRe: Which code you suggest? Pin
nocturns226-Jul-13 3:29
nocturns226-Jul-13 3:29 
AnswerRe: Which code you suggest? Pin
RafagaX26-Jul-13 4:46
professionalRafagaX26-Jul-13 4:46 
AnswerRe: Which code you suggest? Pin
MarkTJohnson26-Jul-13 5:03
professionalMarkTJohnson26-Jul-13 5:03 
One way in, one way out and we stop when we find the value we want.

C#
Boolean DoSomething(string[] values)
        {
           bool bResult = false;
           int i = 0;
           while ( (!bResult) && (i < values.GetLength()) )
           {
              bResult = (values[i++] == "ABC");
           }
           return bResult;
        }   


OR

C#
Boolean DoSomething(string[] values)
        {
           bool bResult = false;
           int i = values.GetLength();
           while ( !bResult && i )
           {
              bResult = (values[--i] == "ABC");
           }
           return bResult;
        }   


Just realized with the my second one, if the array is empty it still works. The first one does too but I like the second better and will try using that logic from now on. Thanks for making me think.
M__k T J.hnnnnn

What my signature looks like in courier.


modified 26-Jul-13 11:11am.

GeneralRe: Which code you suggest? Pin
jibalt26-Jul-13 17:28
jibalt26-Jul-13 17:28 
GeneralRe: Which code you suggest? Pin
MarkTJohnson28-Jul-13 14:41
professionalMarkTJohnson28-Jul-13 14:41 
GeneralRe: Which code you suggest? Pin
BobJanova29-Jul-13 0:17
BobJanova29-Jul-13 0:17 
GeneralRe: Which code you suggest? Pin
jibalt19-Aug-13 23:19
jibalt19-Aug-13 23:19 
GeneralRe: Which code you suggest? Pin
MarkTJohnson20-Aug-13 5:05
professionalMarkTJohnson20-Aug-13 5:05 
GeneralMessage Closed Pin
10-Feb-14 13:17
jibalt10-Feb-14 13:17 
GeneralRe: Which code you suggest? Pin
MarkTJohnson11-Feb-14 4:11
professionalMarkTJohnson11-Feb-14 4:11 
GeneralRe: Which code you suggest? Pin
jibalt26-Jul-13 17:30
jibalt26-Jul-13 17:30 
GeneralRe: Which code you suggest? Pin
PIEBALDconsult30-Jul-13 13:43
mvePIEBALDconsult30-Jul-13 13:43 
GeneralRe: Which code you suggest? Pin
jibalt19-Aug-13 23:25
jibalt19-Aug-13 23:25 
AnswerRe: Which code you suggest? Pin
James Lonero26-Jul-13 13:45
James Lonero26-Jul-13 13:45 
AnswerRe: Which code you suggest? Pin
jibalt26-Jul-13 17:24
jibalt26-Jul-13 17:24 
AnswerRe: Which code you suggest? Pin
jibalt26-Jul-13 17:27
jibalt26-Jul-13 17:27 
AnswerRe: Which code you suggest? Pin
BobJanova29-Jul-13 0:50
BobJanova29-Jul-13 0:50 
AnswerRe: Which code you suggest? Pin
irneb29-Jul-13 3:30
irneb29-Jul-13 3:30 
GeneralRe: Which code you suggest? Pin
jibalt19-Aug-13 23:31
jibalt19-Aug-13 23:31 
AnswerRe: Which code you suggest? Pin
Jonathan C Dickinson29-Jul-13 22:07
Jonathan C Dickinson29-Jul-13 22:07 

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.