function y = it_sum(p, a, r2, it, max_it)
% iter_sum.m
%   assist function for layer_lb.m
%
% Written: Hao Fang
% Created: Nov. 2012

y = 0;
it=it+1;
for ii = (a+1):r2
    if it < max_it
        y = y + p(ii) / (1-p(ii)) * it_sum(p, ii, r2, it, max_it);
    else
        y = y + p(ii) / (1-p(ii));
    end
end

end
