Alternative to "continue"

Answers (2)

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

And in this situation?
Thanks
Yes it does... If I remove the continue, the program will exit the while and go to another step....
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

0 votes

  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

Tags

Asked:

on 6 Dec 2017

Commented:

on 6 Dec 2017

Community Treasure Hunt

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

Start Hunting!