list = [ 50, 40, 30, 20, 10, 77, 99, 10];
% Nminus1 = length(list) - 1;

swapped = true;
while (swapped)
    swapped = false;
    for mat=2:length(list)
        disp(list)
        if (list(mat-1) > list(mat))
            disp(sprintf('swap list items %d and %d', mat-1, mat));
            % swap two values in a row
            temp = list(mat);
            list(mat) = list(mat-1);
            list(mat-1) = temp;
            swapped = true;
        else
            disp('no swap needed');
            
        end
    end
end
