While loop with multiple conditional statements not working
古いコメントを表示
I created this while loop but when I input a fraction that should terminate the loop it doesn't exit the loop.
Ratio=1;
while (Ratio~=0 || Ratio~=(1/2) || Ratio~=1/3 || ...
Ratio~=1/5 || Ratio~=1/11 || Ratio~=5/7)
Ratio=(input('Enter a ratio (parts of milk)/(parts of coffee): '));
if (Ratio~=0 || Ratio~=1/2 || Ratio~=1/3 || ...
Ratio~=1/5 || Ratio~=1/11 || Ratio~=5/7)
disp('Invalid input');
end
end
2 件のコメント
Azzi Abdelmalek
2012 年 9 月 5 日
format your code
Babak
2012 年 9 月 5 日
How can your variable Ratio have multiple values at the same time?
採用された回答
その他の回答 (1 件)
Azzi Abdelmalek
2012 年 9 月 6 日
編集済み: Azzi Abdelmalek
2012 年 9 月 6 日
you will never quit the loop because:
if a~=1 | a~= 2
this expression is always true
maby you should write
if a~=1 & a~= 2
カテゴリ
ヘルプ センター および File Exchange で Programming Utilities についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!