For some reason the code is not repeating.
I want to repeat my input command and the if-else statement. The input has to be positive and must include 0 and not include inf.
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Aldrich Dias
el 22 de Feb. de 2021
Editada: KALYAN ACHARJYA
el 22 de Feb. de 2021
clear;
clc;
A =input('Enter the Code: ');
if A>=0 && A~=inf
B = A;
else
disp('Invalid Code');
while A<0 && A==inf
A =input('Enter the Code: ');
if A>=0 && A~=inf
B = A;
break;
else
disp('Invalid Code');
end
end
end
Respuesta aceptada
KALYAN ACHARJYA
el 22 de Feb. de 2021
Editada: KALYAN ACHARJYA
el 22 de Feb. de 2021
cond=1;
while cond==1
A=input('Enter the Code: ');
if A>=0 && A~=inf
B=A
cond=0;
else
disp('Invalid Code');
end
end
Or
A=input('Enter the Code: ');
while A<0 || A==inf
disp('Invalid Code');
A=input('Enter the Code: ');
end
B=A;
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!