Overwriting While-loop conditional with +Inf
조회 수: 1(최근 30일)
In my code, I have this loop:
while a~=1 && b <= totCycles
I want the loop to run as long as the conditions hold, obviously.
Sometimes, however, I do not want the second condition. I want to effectively make it always true.
Setting totCycles = +Inf looke like the right way to do this, but it doesnt seem to work!
Any ideas why this might be? Or any other workaround?
Andrew Newell 2017년 4월 21일
편집: Andrew Newell 2017년 4월 21일
MATLAB evaluates a logical expression like your while condition from left to right. If a==1, it knows the expression is false and does not even look at the second part. So I suspect that a is a floating point number, and when you think it is equal to 1 it is not exactly equal to 1. See this FAQ.