Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualNypyren

Posted 30 November 2012 - 02:42 PM

I tend to use a "manual break" pattern when I don't want to lift the variable out of the loop. Some people might argue that this is a code smell, but I prioritize "narrowest variable scoping" and "use the least number of variables that work" in this case.

for(;;) // this syntax loops indefinitely, so the only way out is a break, return, or exception.
{
  // stuff
  int result = whatever;

  if (result == x)
	break;
}

#1Nypyren

Posted 30 November 2012 - 02:41 PM

I tend to use a "manual break" pattern when I don't want to lift the variable out of the loop. Some people might argue that this is a code smell, but I prioritize variable scoping and "use the least number of variables that work" in this case.

for(;;) // this syntax loops indefinitely, so the only way out is a break, return, or exception.
{
  // stuff
  int result = whatever;

  if (result == x)
    break;
}

PARTNERS