[DUG] {DUG] break procedure

Brian Wrigley bswrigley at xtra.co.nz
Wed Mar 12 17:08:53 NZDT 2008


Hi John,

----- Original Message -----
From: <johnkbird at paradise.net.nz>
To: <delphi at listserver.123.net.nz>
Sent: Wednesday, March 12, 2008 3:15 PM
Subject: [DUG] {DUG] break procedure


>
> I have been taken by surprise by the break statement - all help says
clearly it
> should exit the current for/while/repeat loop.  I have a block with an
"if"
> block inside a "for" block where break does something different.

That's right, it should break from the loop, not just an inner begin/end
controlled by an if statement. Are you sure it's really going into that
inner block and reaching the break statement? I tried your code snippet in
Delphi 4 (I don't have 5) and it worked as expected, broke right out of the
loop.

> for i:[=]0 to max [do]
> begin
>   .
>   .
>   .
>   if SomeCondition then
>   begin
>     do_something
>     break;
>   end[;]
>   //end of if
>   //more statements executed if did not break out of loop
>   .                <=== break jumps to here
>   .
>   .
> end
>
> in case the above example gets garbled by the email send, the break jumps
out
> of the "if" loop only, not out of the enclosing "for" loop.   The help
says it
> should have jumped out of the "for" loop altogether....
>
> This is the D5 debugger.

Maybe the debugger is getting confused about which breaks it put in and
which ones are yours. What happens if you take out the debugger breakpoints
and put in message boxes instead to show what path is actually being taken
through the code?

Brian



More information about the Delphi mailing list