Consider this simple code
a=[1 1 0 1];recursion(a)
with
function a=recursion(a) if isempty(a) disp('a does not contain 0') else for i=1:numel(a) if a(1)==0 disp('a contains 0') return end a=a(2:end); recursion(a); end endend
Don't focus on the aim of the code (of course the job could be done in 1 line or 2) but on the output
a contains 0a contains 0a contains 0a contains 0ans = 0 1
Is it possibile to output the message "a contains 0" only one time AND then to output the modified vector "a" ? i.e. is it possibile to have this output
a contains 0ans = 0 1
Best Answer