MATLAB: Does the code result in unlimited ans = 1, when that is not in the code

anscodeinfiniteproblemrobotlinefollow

I am trying to get the result of righton, lefton, and input, but when I run the code it creates unlimited ans = 1. When I stop the code with ctrl+c I end up getting the answer I want. Why does "Ans = 1" show up when there is no "Ans" in my code? Here is a picture of my code. my code. Thanks in advance for your help!

Best Answer

The else clause is improperly formed--it cannot have anything as a conditional whereas you've written
else (right & left & center) < thresh
What you're seeing is as if the code were
else
(right & left & center) < thresh
The ans is the result of that comparison.
I haven't read the logic; if you need that actual comparison then need another elseif for it; if it's intended as indicating what the meaning of the else actually is then comment it out like
else % (right & left & center) < thresh
Related Question