is 'continue' in 'c' language similar in MATLAB??
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Friedrich
am 6 Apr. 2013
Bearbeitet: Friedrich
am 6 Apr. 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 Kommentare
Cedric
am 6 Apr. 2013
Bearbeitet: Cedric
am 6 Apr. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!