is 'continue' in 'c' language similar in MATLAB??
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i am changing my code of c language in to matlab .but its gives infinite loop in Matlab during use 'continue' statement?
what is the problem? is there any other alternate of 'continue' statement?
4 commentaires
Réponse acceptée
Friedrich
le 6 Avr 2013
Modifié(e) : Friedrich
le 6 Avr 2013
Hi,
yes continue in MATLAB is the same as in C. However when I look at that while loop:
while j<=n
if j==i
continue;
end
this can`t even work in C. If j == i you will hit an endless loop because j never changes. Maybe you are missing to increment j before the continue statement?
2 commentaires
Cedric
le 6 Avr 2013
Modifié(e) : Cedric
le 6 Avr 2013
No, the problem is precisely here. You increment j after the conditional statement, so your code is looping between the WHILE and the CONTINUE, without ever incrementing j. It would be the exact same in C, unless you had a j++ in either condition.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!