MATLAB: How to ask a for input, and keep asking the same question until the right input is inputted

loop

If I want the user to input an even number, and keep asking the user to input another number if they input an odd number or zero.

Best Answer

One way. n avoids running forever.
%%
n = 0;
while n <= 12
n = n + 1;
x = input('Please, input an even number ');
if x==0
disp('This number is zero, please rerun the programme again, sorry this is not automatic')
elseif mod(x,2) == 0
disp('the number is even')
break
else
disp('This is an odd number, please rerun the programme again, sorry this is not automatic')
end
end