Clear Filters
Clear Filters

How can I restart a loop for the same iteration?

39 views (last 30 days)
KatPa
KatPa on 12 Dec 2017
Commented: KL on 12 Dec 2017
Dear all,
Maybe this question sounds odd, but I wonder how I could restart a if-loop for the same iteration (if the user asks for it).
So right now I draw a figure, then I ask the user what to do (Letters coded in a choice/if loop). And one of the options should be to redraw the figure and give again all the options. I think I have to use a while loop from the beginning, but I am afraid I have no idea how to do that...
Thank you for your help,
Katharina
So atm my code looks a bit like
for ... loop through files
... open file, prepare data, draw figure
choice = input ...
if choice== 'A'
... do stuff with data and exit if loop
if choice== 'B'
... do other stuff with data and exit if loop
if choice== 'C'
... do stuff
... redraw figure and prompt again these options (???)
end
save changed data
end
  2 Comments
KL
KL on 12 Dec 2017
(Letters coded in a choice/if loop)
I'd recommend switch case for this purpose and then you can follow Jos' answer to reset the condition variable.

Sign in to comment.

Answers (1)

Jos (10584)
Jos (10584) on 12 Dec 2017
Use a while loop:
k = 0
while k < N
k = k + 1 ;
... do stuff
if ...
k = 0 ; % start again
end
end

Categories

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

Tags

Community Treasure Hunt

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

Start Hunting!