Q:

Understanding for-loop increment part

Can someone tell what does this mean in for loop.I had seen it somewhere but was not able to understand it.
for (int i = p; i >= 0; i = ((i + 1) & i) - 1){
  //DO SOMETHING
  }

I want to ask meaning for this i = ((i + 1) & i) - 1.How is decrement going here am not able to get it.
Similar to this their is one more i faced : 
  for (int i = p; i < 5; i = (i + 1) | i){
  //DO SOMETHING
  }

What i = (i + 1) | i means here ?
Please explainc++

A:

Following code is in Java, however similar behavior can be expected in C++, C
On closely observing the first loop 
int p = 29; // 30th element if zero indexed
for (int i = p; i >= 0; i = ((i + 1) & i) - 1) {
    System.out.println(Integer.toString(i + 1, 2) + " : " + (i + 1));
}

output :
11110 : 30          -> 30th element    30 -> 16 + 8 + 4 + 2
11100 : 28          -> 28th element    28 -> 16 + 8 + 4
11000 : 24          -> 24th element    24 -> 16 + 8
10000 : 16          -> 16th element

Observe the bit pattern
Similarly for second loop 
int p = 2; // 3rd element if zero indexed
for (int i = p; i < 100; i = (i + 1) | i) {
    System.out.println(Integer.toString(i + 1, 2) + " : " + (i + 1));
}

Output :
11 : 3          -> 3rd element
100 : 4         -> 4th element
1000 : 8        -> 8th element
10000 : 16      -> 16th element
100000 : 32     -> 32nd element
1000000 : 64    -> 64th element

Again observe the bit pattern.
The only place where I have seen such bit pattern is while build dependency tree like Fenwick tree or Bit Indexed Tree. 
Check : http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=binaryIndexedTrees
In the link I guess they have assumed 1-indexed but here 0 indexed hence i adapted position of elements

