Forces a jump out of a single loop System unit
 procedure Break ;
The Break procedure forces a jump out of the setof statements within a loop. Like the Goto statement, it should be used with caution.
The next statement that is executed is the one following the loop terminator. For example:
for i := 1 to 10 do
size := 10;  
// breaks to here

It is important to note that the Break statement only jumps out of the current loop - not out of any nested loops above it. The Goto statement can.
Use with caution.
Related commands
Continue Forces a jump to the next iteration of a loop
Exit Exit abruptly from a function or procedure
For Starts a loop that executes a finite number of times
Goto Forces a jump to a label, regardless of nesting
Repeat Repeat statements until a ternmination condition is met
RunError Terminates the program with an error dialog
While Repeat statements whilst a continuation condition is met
Abort Aborts the current processing with a silent exception
 Author links

 Buy Website Traffic at

 Buy Proxies at
 Download this web site as a Windows program.

Example code : Breaking out of a loop for good reason
  i : Integer;
  s : string;

  s := '';

  // A big loop
  for i := 1 to 10 do
    s := s + IntToStr(i) + ' ';
    // Exit loop when a certain condition is met
    if Random(4) = 2 then Break;

  ShowMessage('i = '+IntToStr(i));
  ShowMessage('s = '+s);
Show full unit code
   i = 6
   s = 1 2 3 4 5 6
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page