In practice, they won’t be identical. It depends on whether every condition is true, or if any of them false. Assuming that you expect the conditions to evaluate as true, then inline conditional if statements are the way to go. But, if you expect it to be more likely that one or more of your conditions will evaluate as false, you should nest your if statements. Try experimenting with the following code:
testOne();
testTwo();
testThree();
testFour();
// ------------------------------------
function testOne() {
var a = true;
var b = true;
var c = true;
var d = true;
startTime1 = getTimer();
for (var i = 0; i < 100000; i++) {
if (a && b && c && d) {
// do something
}
}
trace("All inline conditions are true = " + (getTimer() - startTime1));
}
// ------------------------------------
function testTwo() {
startTime2 = getTimer();
for (var i = 0; i < 100000; i++) {
if (a) {
if (b) {
if (c) {
if (d) {
// do something
}
}
}
}
}
trace("All nested conditions are true = " + (getTimer() - startTime2));
}
// ------------------------------------
function testThree() {
var a = false;
var b = true;
var c = true;
var d = true;
startTime3 = getTimer();
for (var i = 0; i < 100000; i++) {
if (a && b && c && d) {
// do something
}
}
trace("Condition a is false (inline) = " + (getTimer() - startTime3));
}
// ------------------------------------
function testFour() {
var a = false;
var b = true;
var c = true;
var d = true;
startTime4 = getTimer();
for (var i = 0; i < 100000; i++) {
if (a) {
if (b) {
if (c) {
if (d) {
// do something
}
}
}
}
}
trace("Condition a is false (nested) = " + (getTimer() - startTime4));
}