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 次查看(过去 30 天)
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

采纳的回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2021-2-22
编辑:KALYAN ACHARJYA 2021-2-22
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 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by