Decrement on While loops

e is the exponent and that while loop is doubling the value of the number until the exponent is less than or equal to 0.

It will remain the value of i unless it is decremented.

You could also convert it into a for loop like so

for (int e = i; e > 0; e--) { 
    result *= 2;
} 

I understand if this is a learning exercise, but the Math.pow function could do the same thing.

Leave a Comment