function loops = getFeedbackLoops(A,path,loops)
if nargin<3 || isempty(loops)
    loops = {};
end

d = find(A(:,path(end)));
for i = 1:length(d)
    start = find(d(i) == path);
    if start
        if start == 1
            loops{end+1} = path(start:end);
        end
    else
        loops = [loops getFeedbackLoops(A, [path d(i)])];
    end
end