how to run a function again and again till a condition satisfies?

Hello, i have a function which i want to run again and again till the condition is fulfilled.
please please help me....

 Accepted Answer

suchismita, see e.g.,
flag = false;
cnt = 0;
while ~flag
cnt = cnt + 1;
fprintf('Try no.: %d\n', cnt);
if (rand() < 0.25)
flag = true;
end
end
Your function would simply reside inside the loop.

More Answers (1)

Stephen23
Stephen23 on 27 Apr 2015
Edited: Stephen23 on 27 Apr 2015
This is what a while loop is for. There are good examples in the documentation too:
And this is a good place to look when you want to control your program somehow:

Categories

Find more on Programming in Help Center and File Exchange

Tags

No tags entered yet.

Asked:

on 27 Apr 2015

Commented:

on 27 Apr 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!