MATLAB Answers

arwa
0

What is the possible code that can be used to return to primary while?

Asked by arwa
on 23 Dec 2016
Latest activity Commented on by Image Analyst
on 23 Dec 2016
hi, I have this code ;
while(true) % primary while(step 1)
while(true)
if (condition)
statement
...
statement
continue
end
end
while(true)
if (condition)
statement
...
statement
(??) % Here, I want to return to primary while (i.e step 1)
else
end
end
What is the possible code that can be used at (??) mark?

  0 Comments

Sign in to comment.

1 Answer

Answer by Les Beckham on 23 Dec 2016

Use 'break'

  2 Comments

but that won't fix your second while. That loop will never exist because you don't have a break in it, so you'll never even get to the third while. A "continue" merely tosses control to the bottom of the while loop but let's it continue, forever in your case. You should always have a failsafe in your loop conditions to prevent infinite loops.

Sign in to comment.