how to stop executing while loop?

2 次查看(过去 30 天)
x=1;
while x>0
x+1
end
  2 个评论
KSSV
KSSV 2020-10-28
This is an infinite loop...it will not stop....to force stop use ctrl + c .
Ramesh Singh
Ramesh Singh 2020-10-28
i already type this statement and it run , then i type clc clear delete variable it does't work,
thank kssv ctrl+c is right to stop

请先登录,再进行评论。

采纳的回答

KSSV
KSSV 2020-10-28
You can set a condition like below and exit the while loop.
x=1;
while x<10
x = x+1 ;
end

更多回答(1 个)

Alan Stevens
Alan Stevens 2020-10-28
Use a condition inside the while loop, such as
if x>10, break, end

类别

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

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by