ptr[X] equivalent to *(ptr + X) , so we can rewrite it as follows:
for((*(ptr + X))--; *(ptr + X); (*(ptr + X))--, ptr += Y);
Now there is a lot of redundancy here, so we can simplify this:
char *ptr_plus_x = ptr + X; for((*ptr_plus_x)--; *ptr_plus_x; (*ptr_plus_x)--, ptr_plus_x += Y);
Then we can completely get rid of ptr_plus_x :
ptr += X; for((*ptr)--; *ptr; (*ptr)--, ptr += Y);
In English, we visit memory cells at offsets X, X + Y, X + 2Y, X + 3Y, ..., decreasing each memory cell until we find a memory cell that is 0. But the test for 0 always happens after decrement , so we are really looking for the first memory location in this sequence with a value of 1. As soon as we find this, we will reduce it to 0 and stop.
If Y is 1, then we reduce the line of consecutive memory locations going forward, up to and including the first. If Y is -1, the same thing happens, but a search is performed backward from the offset X. If Y is 0, an infinite loop occurs. If Y is any other value, the search pattern skips the various entries.
This is not a very intuitive feature, so I can understand why you are confused.