Click here to Skip to main content
15,887,027 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Twitter sues Elon Musk Pin
MikeCO1014-Jul-22 2:37
MikeCO1014-Jul-22 2:37 
GeneralRe: Twitter sues Elon Musk Pin
OriginalGriff14-Jul-22 3:07
mveOriginalGriff14-Jul-22 3:07 
GeneralRe: Twitter sues Elon Musk Pin
Kirk 1038982114-Jul-22 8:14
Kirk 1038982114-Jul-22 8:14 
GeneralRe: Twitter sues Elon Musk Pin
zezba900014-Jul-22 7:45
zezba900014-Jul-22 7:45 
GeneralYou know you need more coffee when... Pin
Chris Maunder12-Jul-22 14:30
cofounderChris Maunder12-Jul-22 14:30 
GeneralRe: You know you need more coffee when... Pin
Super Lloyd12-Jul-22 14:41
Super Lloyd12-Jul-22 14:41 
GeneralRe: You know you need more coffee when... Pin
Southmountain12-Jul-22 15:17
Southmountain12-Jul-22 15:17 
GeneralRe: You know you need more coffee when... Pin
trønderen13-Jul-22 12:46
trønderen13-Jul-22 12:46 
One of the rules I follow when programming is never to make infinite loops. For-loops with an explicit test on an iteration counter are reasonably "safe", and I prefer those when they don't mess up too much.

Sometimes while-loops come a lot more natural. Unless there are other explicit and obvious tests that guarantee loop termination, regardless of (loop) external conditions, I always add something like
C#
int iterationCount = 0;
while (<some 'unsafe' condition>) {
  if (iterationCount++ > 10000) break;
The limit is arbitrarily chosen, but must of course be larger than the actual iteration count in any 'normal' situation. If the loop still runs after (say) 10000 iterations, something is surely wrong.

Yes, it takes two extra lines. It takes a couple of extra instructions for each iteration. But it makes sure that the code never is stuck in an infinite loop when it shouldn't.
GeneralRe: You know you need more coffee when... Pin
englebart13-Jul-22 14:28
professionalenglebart13-Jul-22 14:28 
GeneralRe: You know you need more coffee when... Pin
jmaida12-Jul-22 15:29
jmaida12-Jul-22 15:29 
GeneralRe: You know you need more coffee when... Pin
trønderen13-Jul-22 13:09
trønderen13-Jul-22 13:09 
GeneralRe: You know you need more coffee when... Pin
jmaida13-Jul-22 15:31
jmaida13-Jul-22 15:31 
GeneralRe: You know you need more coffee when... Pin
trønderen13-Jul-22 19:25
trønderen13-Jul-22 19:25 
GeneralRe: You know you need more coffee when... Pin
jmaida14-Jul-22 9:31
jmaida14-Jul-22 9:31 
GeneralRe: You know you need more coffee when... Pin
jmaida14-Jul-22 10:51
jmaida14-Jul-22 10:51 
GeneralYou know you're no more a nerd when... Pin
CPallini12-Jul-22 20:07
mveCPallini12-Jul-22 20:07 
GeneralRe: You know you're no more a nerd when... Pin
englebart13-Jul-22 15:35
professionalenglebart13-Jul-22 15:35 
GeneralRe: You know you're no more a nerd when... Pin
trønderen13-Jul-22 19:37
trønderen13-Jul-22 19:37 
GeneralRe: You know you're no more a nerd when... Pin
englebart22-Jul-22 5:53
professionalenglebart22-Jul-22 5:53 
GeneralRe: You know you need more coffee when... Pin
Marc Clifton13-Jul-22 2:39
mvaMarc Clifton13-Jul-22 2:39 
GeneralRe: You know you need more coffee when... Pin
CPallini13-Jul-22 3:23
mveCPallini13-Jul-22 3:23 
GeneralRe: You know you need more coffee when... Pin
trønderen13-Jul-22 12:29
trønderen13-Jul-22 12:29 
GeneralRe: You know you need more coffee when... Pin
Gary R. Wheeler13-Jul-22 14:47
Gary R. Wheeler13-Jul-22 14:47 
GeneralRe: You know you need more coffee when... Pin
englebart13-Jul-22 15:43
professionalenglebart13-Jul-22 15:43 
GeneralRe: You know you need more coffee when... Pin
obermd13-Jul-22 4:07
obermd13-Jul-22 4: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.