how to stop executing while loop?

x=1;
while x>0
x+1
end

2 Comments

This is an infinite loop...it will not stop....to force stop use ctrl + c .
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

Sign in to comment.

 Accepted Answer

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

More Answers (1)

Use a condition inside the while loop, such as
if x>10, break, end

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Release

R2019b

Tags

Asked:

on 28 Oct 2020

Commented:

on 28 Oct 2020

Community Treasure Hunt

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

Start Hunting!