Bubble sort is composed of two loops, one inside the other, the idea is to push the largest number on the right most side of the list, one by one.
For the sake of discussion, we'll call a
the outer loop and b
the inner loop.
a
starts atlist.length - 1
, last step occurs at0
.b
starts at0
, last step occurs ata - 1
, i.e., ifa = 3
, then last step ofb
would be2
.