While attempting to address the following inquiry, I stumbled upon an unusual loop condition.
for (index1 = 1; index1 < 8; index1++) {
var op = '#';
for (index2 = index1; index2 - 1; index2--) { //this loop is weird to me
op = op + '#';
}
console.log(op);
}
Upon evaluating the number of iterations the inner loop goes through during each iteration of the outer loop, the results are as follows:
var x = 0;
for (index1 = 1; index1 < 8; index1++) {
//var op = '#';
for (index2 = index1; index2 - 1; index2--) {
var log = {};
log.a = x; //check value before increment
x++;
log.b = x; //check value after increment
console.log(`outer: ${index1}, inner: ${index2}`, log);
}
console.log(x);
x = 0;
//console.log(op);
}
As observed, it displays 0, 1, 2, 3, 4, 5, 6
.
Therefore, my query is:
Could the reason the inner loop does not iterate during the first outer loop cycle be due to
index2 - 1
equating to zero, which evaluates as falsy?