MATLAB: Using “WHILE” to compare input value with positive integer

while loop

I want to make a better code. The user will be asked for a number, if the value is not a positive integer, the program should ask again.
a=-1.5;
while a<0
while a/ceil(a)~=1;
a=input('How many items?');
end
if a<0 a=-1.5; end
end
I think i can simplify the coding, (maybe using some &&, or something like that) I just dont know how. Thanks in advance

Best Answer

a=-1;
while abs(a)/ceil(a)~=1
a=input('How many items?');
end
%if you allow nul value
a=-1;
while abs(a)~=ceil(a)
a=input('How many items?');
end
Related Question