while(y) Executes until y is false. In the case of a boolean this is obvious, but here y is an integer. Implicit int->bool conversion produces false only if the integer is 0. Anything else and the expression is true. Since you're using integer division, any results will be rounded DOWN. So if y < 1, y > 0 it will simply be rounded to 0, and your loop will be false.
The condition expression in the while statement is converted to a bool expression. For conditions of an integral type any value that is not equal to zero is converted to true. Otherwise it is converted to false.
So for the first iteration the value of the expression ( y ) is equal to 2 that is unequal to zero. So it is converted to true. Inside the body of the loop y becomes equal to 1 after the statement y = y/2;
So in the next iteration of the loop the condition expression again is not equal to zero and is converted to true. At this time in the loop body y becomes equal to 0 ( y = 1 / 2 ). So in the next iteration of the loop the condition expression is equal to zero and is converted to false. The loop will not executed any more. Thus the loop was executed two times until y has become equal to zero.