Alternative to "continue"

7 Ansichten (letzte 30 Tage)
João Carvalho
João Carvalho am 6 Dez. 2017
Kommentiert: Walter Roberson am 6 Dez. 2017
Hello, is there any alternative to that continue?

Antworten (2)

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

Melden Sie sich an, um zu kommentieren.


Guillaume
Guillaume am 6 Dez. 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.

Kategorien

Mehr zu Performance and Memory finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by