Logical operators not working inside while loop
1 回表示 (過去 30 日間)
古いコメントを表示
I have wrote conditions inside while loop using logical operators.
my program is
p=12;
while (p~=1) | (p~=2)
imshow(image.jpg);
end
but an infinite loop is running
I am unable to find the bug in this. Please help.
0 件のコメント
採用された回答
Sean de Wolski
2013 年 1 月 29 日
Well you never change p so it is always 12!
x = 10;
while x~=1
x = x-1;
disp(x)
end
Alternatively you can use a for-loop:
for ii = 10:-1:1
disp(ii);
end
0 件のコメント
その他の回答 (2 件)
Jan
2013 年 1 月 29 日
Yes, of course this is in infinite loop: The value of p does not change inside the loop.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!