Filter löschen
Filter löschen

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 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Voss
Voss am 10 Mär. 2023
while true
bin = input('Input binary number: ','s');
if ~all(bin == '0' | bin == '1')
break
end
D = bin2dec(bin)
% ...
end

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by