samedi 27 novembre 2021

Question regarding post decrement in loop jointed with if

What is the difference between the following to code? The result is different. b is some String and int j = b.length() - 1

The if branch is in a loop and runs many times if this makes any difference.

if (j >=0 && b.charAt(j) == '1') {
    j--;
    carry ++;
}

vs.

if (j >=0 && b.charAt(j--) == '1') {
    carry ++;
}

Aucun commentaire:

Enregistrer un commentaire