If , while with or

3 次查看(过去 30 天)
jamaledin
jamaledin 2012-12-11
How can I put or in "IF, While" function. For example:
While a<b or C<d
...
Cheers,
  1 个评论
Jan
Jan 2012-12-11
Reading the documentation has massive advantages.

请先登录,再进行评论。

回答(1 个)

Matt Fig
Matt Fig 2012-12-11
Did you look at the documentation?
doc while
In the documentation are examples.
a = 1;
b = 10;
c = 20;
d = 10000;
while a<b | c<d
a = a + 1;
c = c * a;
end
  3 个评论
Walter Roberson
Walter Roberson 2012-12-11
In new versions (R2012a and later I think it is), "if" and "while" automatically short-circuit "|" and "&" operations with scalar arguments. This does not apply to "|" and "&" in any other logical expression
Jan
Jan 2012-12-11
@Walter: The | operator in IF expressions apply short-circuiting in Matlab 6.5 already. As far as I remember in WHILE also.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by