MATLAB Answers

jamaledin
0

If , while with or

jamaledin
さんによって質問されました 2012 年 12 月 11 日
How can I put or in "IF, While" function. For example:
While a<b or C<d
...
Cheers,

  1 件のコメント

Jan
2012 年 12 月 11 日
Reading the documentation has massive advantages.

サインイン to comment.

タグ

1 件の回答

Login_Name
回答者: Login_Name
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 件のコメント

TAB
2012 年 12 月 11 日
Shouldn't it be like this ; )
while a<b || c<d
a = a + 1;
c = c * a;
end
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
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.

サインイン to comment.



Translated by