Clear Filters
Clear Filters

for loop start from first operation if df=1?

1 view (last 30 days)
Arunachalam  D
Arunachalam D on 14 Jul 2015
Answered: Geoff Hayes on 14 Jul 2015
For a=1:20
Df=0;
If condition
Operation(a);
Condition reset;
Df=df+1;
End
If df==1
Repeat for loop again how to do it
End

Answers (1)

Geoff Hayes
Geoff Hayes on 14 Jul 2015
Arunachalam - I think that you may be able to repeat the above if you use a while loop. Something like
a = 1;
while a <= 20
if condition
Operation(a);
% Condition reset;
a = 1;
else
a = a + 1;
end
end
Not sure if the above is what you have intended but look how we just use a and not the Df to continue iterating or to restart the loop if some condition is met.
Note that the above code is dangerous as you could get stuck in an infinite loop. You may want to decide how many reset of a to one you should allow before terminating the while loop.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!