Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Mashi
Aug 15, 2005

Just wanted you to know your dinner's cold and the children all agree you're a shitheel!

aeiou posted:

I have seen this a couple times in code at work and i fail to understand HOW people come up with this. And then afterword not realize that they could just have put all the statements in a row? Am I missing something here?

Being in a loop, you get to make use of the break keyword, and you have an iterator variable (i) which indicates which step was achieved... I used it once or twice like that anyway.

Adbot
ADBOT LOVES YOU

Mashi
Aug 15, 2005

Just wanted you to know your dinner's cold and the children all agree you're a shitheel!

DaTroof posted:

Are you serious? I have trouble imagining how that's more practical than something like this:

code:
function forCase() {
	if (firstProcess()) {
		return a;
	}
	if (secondProcess()) {
		return b;
	}
	if (thirdProcess()) {
		return c;
	}
}
Especially since a, b, and c can be made into something more useful than an iterator value with a vague and possibly transient meaning.

AI saw it as a way to avoid nesting an IF statement 6 levels deep. I never said it was good I just offered some possible reasoning for doing it. Also I am self taught so yea I used to do alot of weird and zany poo poo...

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply