Think about it: what did you expect it to do? If you could change the number 1 to say 43 and get no change in the results, then adding any number is irrelevant, and that is surely not the case.
Look at "your" code:
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j +1] = key;
It's a loop, which iterates until either
j
is negative, or the array element at index
j
is less than or equal to the value in
key
So you need something inside the loop to alter the value of
j
, or
key
, or both.
Since you don't want
key
to alter,
j
much change or the loop will continue forever.
And that's what this like does:
j = j - 1;
It subtracts one from the current value of
j
and stores the result back into
j
.
If you changed the value in this line from 1 to 43 then it would loop round a lot fewer times, and look at a lot fewer array elements!
(It can be written shorter:
j--;
does exactly the same thing.)
The other line inside the loop is simpler: it's "moving" each element of the array into the element above it.
Try it on paper and you'll see what I mean.