Clear Filters
Clear Filters

while loop keeps running indefinitely

1 view (last 30 days)
Why my code is not working? It keeps running indefinitely...
z0=[0.3 0.5 0.2];
test=0;
while test==0
disp('checking');
if exp(z0(2)*(1-z0(1)))<(1/z0(3))
z0=z;
else
r1 = 0 + (1-0).*rand(1,1);
r2= 0 + (10-0).*rand(1,1);
r3= 0 + (1-0).*rand(1,1);
z0=[r1 r2 r3];
end
test=0;
end

Accepted Answer

James Tursa
James Tursa on 21 Aug 2013
You never set test to anything other than 0, so the loop condition is always true.

More Answers (0)

Categories

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

Tags

Community Treasure Hunt

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

Start Hunting!