continue, how to skip part of a cycle

6 vues (au cours des 30 derniers jours)
OldCar
OldCar le 5 Oct 2016
Commenté : OldCar le 6 Oct 2016
I have this code, that is supposed to skip to the following k value when count reaches 3
clear
clc
p=0;
for k=1:10
count=0;
while k-p>3
k
p=p+0.25;
count=count+1;
if count>=2
continue
end
end
end
but it doesn't happen.
What haven't I understood?
Many thanks

Réponse acceptée

James Tursa
James Tursa le 6 Oct 2016
Modifié(e) : James Tursa le 6 Oct 2016
Your if-test and continue statement are inside the inner while loop, so they apply to that loop, not the for-loop. Maybe use a break to get out of the while loop if that is what you want to do. (The way you have it coded, the continue statement does nothing since it simply goes to the next iteration of the while loop and isn't skipping over any code)
  1 commentaire
OldCar
OldCar le 6 Oct 2016
Many thanks, short but clear!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by