MATLAB Answers

Constructing a try-catch loop

34 views (last 30 days)
Hi,
I am trying to write a try-catch loop that will only fail on more than five attempts. how can i go about that?
So far, I have: try
%command to execute
catch
command to execute if error
end
how can i make this a loop that will only fail after five attempt at maximum?
any help would be appreciated,
sushma

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 21 May 2017
Edited: Walter Roberson on 21 May 2017
fail_count = 0;
for fail_count = 1 : 5
try
THIS
break; %stop on first success
catch
if fail_count == 5
THAT
end
end
end

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.