Reputation: 13
I ran across this piece of Borland Pascal code. I am curious as to how this does not repeat endlessly.
repeat
if xs>(torgx+xlim)
then begin
x:=xlim;
BREAK;
end;
if xs<(torgx-xlim)
then begin
x:=0-xlim;
BREAK;
end;
x:=xs-torgx;
BREAK;
until 0<>0;
I am confused as to how zero would ever be greater than or less than zero.
Upvotes: 1
Views: 83
Reputation: 34949
A loop that continues until 0 <> 0
is supposed to be endless.
But inside the loop there are some conditions that will break the loop, hence the use of the keyword break
.
In fact, the repeat..until
loop will only run once. The comparison is made that if a value is larger than a condition or less than another it will break out of the loop. If none of those conditions are met, it will break anyway.
Upvotes: 2