Alternative to "continue"

조회 수: 8 (최근 30일)
João Carvalho
João Carvalho 2017년 12월 6일
댓글: Walter Roberson 2017년 12월 6일
Hello, is there any alternative to that continue?

답변 (2개)

Image Analyst
Image Analyst 2017년 12월 6일
You could wrap everything in an if
for .......
if m == 0
% Code you want to run
else
fprintf('O Username deve .............
end
end
That doesn't use a continue.
  댓글 수: 3
João Carvalho
João Carvalho 2017년 12월 6일
Yes it does... If I remove the continue, the program will exit the while and go to another step....
Walter Roberson
Walter Roberson 2017년 12월 6일
The code you display here has no way to exit the while loop, because nothing changes x . We must suspect that after the if m ~= 0 that you have more code that might change x, with the general structure
while x == true
some code here
if m ~= 0
display error
continue;
end
some more code here
end
You would change that to
while x == true
some code here
if m ~= 0
display error
else
some more code here
end
end

댓글을 달려면 로그인하십시오.


Guillaume
Guillaume 2017년 12월 6일
  1. Why do you ask?
  2. Programming languages are efficient. This means that if there is an instruction to do something, there's not going to be another one to do the exact same thing.
  3. Maybe there is an alternative but that would depend on the for loop that encloses the piece of code you've shown, so you've not even shown enough code to answer your question.

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by