Jump to content

  • Log In with Google      Sign In   
  • Create Account

14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!

#ActualÁlvaro

Posted 01 December 2012 - 03:35 PM

for (int bar =0; bar < 100; ++bar)
{
	 for(int foo = 0; foo < 100; ++foo)
	 {
		  if (foo * bar == 100)
		  {
			   foo = 100;
			   bar = 100;
			   continue;
		  }
	 }
}
printf("%d", 100);


So instead of a goto whose purpose is immediately obvious (you even get a label in whose name you can document what's going on), now we have code which expresses intent worse and requires changing the ranges in two places if they ever change. What if we now want to do something when the loops end without the condition ever being found? With the goto, you just put that code before the label; with the new code, there is really no obvious way of doing it. What if we are interested in knowing the values of foo and bar whose product is 100 beyond the loop? Again the old code was easier to adapt.

The only "advantage" of the second code is that it doesn't use goto, which as far as I am concerned is a ridiculous metric.

#1Álvaro

Posted 01 December 2012 - 03:34 PM

for (int bar =0; bar < 100; ++bar)
{
	 for(int foo = 0; foo < 100; ++foo)
	 {
		  if (foo * bar == 100)
		  {
			   foo = 100;
			   bar = 100;
			   continue;
		  }
	 }
}
printf("%d", 100);


So instead of a goto whose purpose is immediately obvious (you even get a label in whose name you can document what's going on), now we have code which expresses intent worse and requires changing the ranges in two places if they ever change. What if we now want to do something when the loops end without the condition ever being found? With the goto, you just put that code before the label; with the new code, there is really no obvious way of doing it.

The only "advantage" of the second code is that it doesn't use goto, which as far as I am concerned is a ridiculous metric.

PARTNERS