How do I break a loop? EX:
for x:=1 to 10 do
if x = 5 then "break"
end
When it got to 5, the loop would be broken, would not continue. Of course it would be another condition. I wonder if you have any.
How do I break a loop? EX:
for x:=1 to 10 do
if x = 5 then "break"
end
When it got to 5, the loop would be broken, would not continue. Of course it would be another condition. I wonder if you have any.
The command to break or break a loop in Delphi is break
.
Using your code as an example:
for x:=1 to 10 do
begin
if x = 5 then
Break;
end;
x = 5; // nesta linha, x de fato será 5.
This command can be used to break any loop structure, such as while
and repeat
.
A break
command breaks only the loop in which it is contained. If one loop is contained in another, the outer loop will not be broken by the break
command executed in the inner loop.
for x:=1 to 10 do
if x = 5 then break;
end