is 'continue' in 'c' language similar in MATLAB??
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Friedrich
el 6 de Abr. de 2013
Editada: Friedrich
el 6 de Abr. de 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 comentarios
Cedric
el 6 de Abr. de 2013
Editada: Cedric
el 6 de Abr. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!