Yeah you are right,now calculated value is assigned to x,after which the loop continues,i.e.,
Int bar(int val){
While(val>0)
{
x=x+bar(val-1);
/*after x=0+0; the loop is checked again,as value of val is 1 in this activation record(current function),while condition becomes true again ((val)1>0).it enters the loop again bar(val(1)-1) is called i.e., bar(0) which in turn returns 0,again x=0+0; again checks the loop,again calls ....*/
}
return val;/*this line gets executed only when the while loop becomes false.*/
}
Note: you have to re-trace to clearly understand,that return 0 happens only when while loop becomes false,in our case only when bar(0) is called while loop becomes false.