Borrar filtros
Borrar filtros

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 visualizaciones (últimos 30 días)
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

Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by