Breaking a For Loop

1

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.

    
asked by anonymous 17.10.2014 / 19:02

2 answers

4

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.

    
17.10.2014 / 19:24
3
for x:=1 to 10 do
if x = 5 then break;
end
    
17.10.2014 / 19:10