0

I am aware of the general syntax for the while loop in matlab, which general includes

While statement Do expression things End

But what does

while (1) 
...

mean?

Why is there a (1), and no relational Or logic operator?

2
  • 2
    1 is always true. The while loop never ends. It’s an infinite loop. Commented Feb 11, 2020 at 2:31
  • You need a break statement to terminate the execution of the while (1) loop Commented Feb 11, 2020 at 9:19

1 Answer 1

1

Every time you use structures like "while" or "if" they have a condition inside the parenthesis. If that condition is true, the code inside is executed. Something being true translates to the Boolean 1. Try this command in Matlab:

3>2

Matlab will tell you that this statement is a true with the Boolean answer '1'. If you put while(1), it is the same as putting while(3>2), both statements are always true, so the code inside is going to be executed an infinite amount of times (if there aren't any command inside that loop that might break it).

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.