0

How can I make a while loop condition that is true when x is NOT 1 or 2, and only those two numbers? I'd imagine it going something like this

while x ~= (1 || 2)
%blablabla
end

But that doesn't work in practice. How can I correctly write this?

1 Answer 1

2

Put while x~=1 && x~=2.

(1 || 2) will always be true and therefore the while loop is never entered. Logical expressions with double values in MATLAB classify as true everything that is non-zero (like 1 and 2) and everything that is zero as false

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.