Are these two loops the same? For some reason the second loop is off-by-one and I cannot figure out why.
while ( !b && ++n < WORD_COUNT ) b = mWords[n];
n++;
while ( !b && n < WORD_COUNT ) {
b = mWords[n];
n++;
}
Are these two loops the same? For some reason the second loop is off-by-one and I cannot figure out why.
while ( !b && ++n < WORD_COUNT ) b = mWords[n];
n++;
while ( !b && n < WORD_COUNT ) {
b = mWords[n];
n++;
}
When the predicate
bwas not successful, then a logic short-circuit may apply in the first form and the final increment ofnmay be skipped.In the second form, the increment happens before predicate
bis evaluated, sonis off-by-one when the loop exits.