Quote Originally Posted by carlorfeo View Post
hello
take these two function examples which should do the same thing:
Code:
// standard way
bool function () {
	if (a == 0) {
		return false;
	}
	else if (a > 0){
		return max (a);
	}
	else {
		return min (a);
	}
}

// non-standard way
bool function () {
	if (a == 0) {
		return false;
	}
	if (a > 0) {
		return max (a);
	}
	return min (a);
}
It's obvious that the first way is easier to read and way better to do things
I am wondering if the second way would be faster once compiled, or not.
I'd say the first way is better.
In this particular case you have return statements in the if statements, so it wouldn't make much difference, but if you didn't return, the first method would skip all other else statements as soon as it finds one that evaluates to true, while the 2nd example would evaluate every if statement.