Following True or False?
1 view (last 30 days)
Show older comments
Consider the following example. a and b are two random variables. The loop will exit if and only if a+b=1. Is it true or false?
a=rand;
b=rand;
while(a+b == 1)
a=rand;
b=rand;
end
Accepted Answer
Walter Roberson
on 27 Aug 2012
While executes as long as the given condition is true, so the loop would only execute as long as the sum was 1.
Note: please take time to review the following: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
5 Comments
Walter Roberson
on 27 Aug 2012
a=rand;
b=rand;
while(a+b ~= 1)
a=rand;
b=rand;
end
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!