How can I restart a loop for the same iteration?

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 commentaires

Birdman
Birdman le 12 Déc 2017
Share your code please.
KL
KL le 12 Déc 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.

Connectez-vous pour commenter.

Réponses (1)

Use a while loop:
k = 0
while k < N
k = k + 1 ;
... do stuff
if ...
k = 0 ; % start again
end
end

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Tags

Question posée :

le 12 Déc 2017

Commenté :

KL
le 12 Déc 2017

Community Treasure Hunt

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

Start Hunting!

Translated by