-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Mon, 12 Oct 2015 15:11:18 -0400, Wkitty42 ()
wrote about "Re: [fpc-devel] Fwd: While - Otherwise Statement" (in ):
Show quoted text 12 lines
On 10/12/2015 02:02 PM, Dmitry Boyarintsev wrote:
>
> The next step would probably be controlled "break", where a user
> would be able to specify how many nested loops needed to broken
> from.
ROTFLMAO! if you need or desire something like that then set a
breakcounter and break... in the next outer block, check
breakcounter to see if you need to break again... if so,
dec(breakcounter) and break... then check it again in the next
outer block... and so on and so on until breakcounter=0... why
should the compiler have to do your logic work for you? ;)
Hi Mark,
You might have seen me write things like this in the old OS2PROG echo of Fidonet some 20+ years ago. ... :-)
The only language I know that offers that level of control is PL/I, where the break statement is coded as LEAVE. It is handled by labelling the loop control statement and coding the required label in the LEAVE statement. For example:
loop_1: DO i = 1 TO m;
loop_2 : DO j = 1 TO n;
loop_3: DO k = 1 TO p;
...
IF some_condition THEH
LEAVE loop_3;
...
IF another_condition THEH
LEAVE loop_2;
...
IF some_other_condition THEH
LEAVE loop_1;
...
END loop_3;
END loop_2;
END loop_1;
If the label is omitted then the immediately containing loop is left.
This allows any of the nested loops to be escaped, potentially all the way out. I guess the corresponding syntax in a Pascal-esque style would be:
loop_1: FOR i := 1 TO m DO
BEGIN
loop_2: FOR j := 1 TO n DO
BEGIN
loop_3: FOR k := 1 TO p DO
BEGIN
...
IF (some_condition) THEN
BREAK loop_1;
...
IF (another_condition) THEN
BREAK loop_2;
...
IF (some_other_condition) THEN
BREAK loop_3;
END
END
END;
If we're being strictly Pascal, the labels would need to be declared at the head of the procedure -- and if we're really strict they should be numeric.
- --
Regards,
Dave [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iEYEARECAAYFAlYcMQMACgkQogYgcI4W/5Sl3wCgtG87fG2aCEuxkVCUrBCmxwCm fSkAoNgXwMSNA/R4AKjDEZsNktglOqvF
=m3vh
-----END PGP SIGNATURE-----