フィルターのクリア

I need my code to loop while my input is binary (ones and zeros). once the user inputs any other value then the loop should stop.

2 ビュー (過去 30 日間)
bin = input('Input binary number: ','s');
index = 1;
while index >= length(bin) | index <= length(bin);
D = bin2dec(bin)
bin = input('Input binary number: ','s');
end
% this is my current code but it is not ending properly. it is ending because of an error rather then the loop ending

採用された回答

Voss
Voss 2023 年 3 月 10 日
while true
bin = input('Input binary number: ','s');
if ~all(bin == '0' | bin == '1')
break
end
D = bin2dec(bin)
% ...
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by