%% Exit Loop Before Expression Is False
% Sum a sequence of random numbers until the next random number is greater than an upper limit. Then, exit the loop using a break statement.

limit = 0.8;
s = 0;

while 1
    tmp = rand;
    if tmp > limit
        break
    end
    s = s + tmp;
end

% Copyright 2015 The MathWorks, Inc.