How do I restart my code again if the conditions are not satisfied

2 次查看(过去 30 天)
Hi guys
Please is there any code that will make me restart a coding process. for instance I have a running code and finalised it with the if statement
if ( x > 1)
disp( ' yoga')
else
disp ( continue running the code until x > 1)
end
how do I run my previous code again until x > 1
Thanks in advance for you kind assistance
regards
  2 个评论
Dennis
Dennis 2019-4-15
In your example x never changes.
There are several ways to accomplish this. You could for example use loops or call your function again (recursive).
x=0;
while x<=1
%do stuff, there should be something here that actually changes the value of x!
end
disp('yoga')

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by