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.

1 view (last 30 days)
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

Accepted Answer

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

More Answers (0)

Categories

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

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!