Alternative to "continue"

2 views (last 30 days)
João Carvalho
João Carvalho on 6 Dec 2017
Commented: Walter Roberson on 6 Dec 2017
Hello, is there any alternative to that continue?

Answers (2)

Image Analyst
Image Analyst on 6 Dec 2017
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 Comments
João Carvalho
João Carvalho on 6 Dec 2017
Yes it does... If I remove the continue, the program will exit the while and go to another step....
Walter Roberson
Walter Roberson on 6 Dec 2017
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

Sign in to comment.


Guillaume
Guillaume on 6 Dec 2017
  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.

Categories

Find more on Performance and Memory in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!