MATLAB: Need some assistance with “if” command

if statement

I'm trying to get my program to stop completely when given an invalid response after entering the side lengths. I've created the following:
a=input('Enter value for side a: ');
if a < 0
disp('Not a valid input.')
end
b=input('Enter value for side b: ');
if b < 0
disp('Not a valid input.')
end
c=input('Enter value for side c: ');
if c < 0
disp('Not a valid input.')

Best Answer

If you don't have a function or anything to return from, there's a sneaky little trick you can use. This can be useful for other things too...
ok = false;
while 1
a=input('Enter value for side a: ');
if a < 0, break; end
b=input('Enter value for side b: ');
if b < 0, break; end
c=input('Enter value for side c: ');
if c < 0, break; end
ok = true;
break;
end
if ok
% Do your thing here....
else
disp('Not a valid input.');
end
Err... Bear in mind this isn't the best of programming practices. =)