Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2015-10

Fwd: While - Otherwise Statement

26 messages · 12 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Max Nazhalov
schrieb "Dmitry Boyarintsev" wrote 6 lines
About while-then. While the syntax is unlikely to break anything, it's inconsistent with if-statement. where, if-then is executed when condition is true. For while-then is executed then condition is false. Thus, while-else or while-otherwise are better. However, both syntax would cause code incompatibility.

I doubt "while-else" is a variant, due to dangling "else".

How will be compiled, e.g.
if something then
  while not_done_yet do
    the_work
else // obviously valid, and expected to be a part of "if-then-else"
  something_else_happened;

---
WBR, Max.

Reply by email

Michael Van Canneyt
to Max Nazhalov
Max Nazhalov wrote 17 lines
On 12.10.2015 17:17 schrieb "Dmitry Boyarintsev" wrote: > About while-then. While the syntax is unlikely to break anything, it's > inconsistent with if-statement. > where, if-then is executed when condition is true. > For while-then is executed then condition is false. > Thus, while-else or while-otherwise are better. However, both syntax would > cause code incompatibility. I doubt "while-else" is a variant, due to dangling "else". How will be compiled, e.g. if something then while not_done_yet do the_work else // obviously valid, and expected to be a part of "if-then-else" something_else_happened;

That is the meaning of "However, both syntax would cause code incompatibility." and is already in my very first reply to OP.

So While... else or While .. Otherwise will never make it in the compiler.

Michael.

Reply by email

Ralf Quint
to Michael Van Canneyt
Michael Van Canneyt wrote 7 lines
That is the meaning of "However, both syntax would cause code incompatibility." and is already in my very first reply to OP. So While... else or While .. Otherwise will never make it in the compiler.

Thanks for that.

This is s typical example of one of those things that just don't make any sense in the first place.

Either the while loop is executed or it isn't, depending in the expression. I don't see an actual use case for any else/otherwise extension to it...

Ralf

---
This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Reply by email

Dmitry Boyarintsev
to Ralf Quint
Ralf Quint wrote 5 lines
Either the while loop is executed or it isn't, depending in the expression. I don't see an actual use case for any else/otherwise extension to it...

You probably want to reread python while-else implementation. ( https://docs.python.org/2/reference/compound_stmts.html) "Else" becomes sort of "part of the loop". Thus if you break out of the loop, "else" would not be executed.
However, if no break occurs "else" part would be executed.

It might be a rare case where it's needed. (I cannot think of any), but to achieve exactly the same functionality in Pascal either of two options should be used.

1) make an extra check if break occurred.

breakflag:=false;
while cond do
  if someothercond then begin
    breakflag : =true;
    break;
  end;
if not breakflag then
  while_else_code

2) use goto! :)

label postElseLabel

while cond do
  if someothercond then begin
     goto  postElseLabel
  end;

while_else_code
:postElseLabel

thanks,
Dmitry

Reply by email

Ralf Quint
to Dmitry Boyarintsev
Dmitry Boyarintsev wrote 12 lines
On Mon, Oct 12, 2015 at 1:35 PM, Ralf Quint < > wrote: Either the while loop is executed or it isn't, depending in the expression. I don't see an actual use case for any else/otherwise extension to it... You probably want to reread python while-else implementation. (https://docs.python.org/2/reference/compound_stmts.html)

Sorry, we are programming here in Pascal, not Python. I could give a rodent's posterior about what Python implements.

People need to properly design their software, not just hacking away. Then they do not need to come up with whacko stop-gaps to fix what could have been done properly in the first place...

Ralf

---
This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Reply by email

Dmitry Boyarintsev
to Ralf Quint
Ralf Quint wrote 7 lines
Sorry, we are programming here in Pascal, not Python. I could give a rodent's posterior about what Python implements. People need to properly design their software, not just hacking away. Then they do not need to come up with whacko stop-gaps to fix what could have been done properly in the first place...

Well, from fpc-devel list perspective your only hope is that any new feature is added via MODESWITCH. Thus any existing unit would be kept clean. You would also be able to keep your libraries clean, by not allowing using of a certain modeswitches.

However, if you look at the recent (for the past few months) discussions, you might spot that the number of requests for new features (from recent Delphi and other languages) is growing. Constantly.

In this particular case it's even worse (actually it's better, from fpc-devel POV), since the patch has been provided.

The next step would probably be controlled "break", where a user would be able to specify how many nested loops needed to broken from.

thanks,
Dmitry

Reply by email

Mark Morgan Lloyd
to Ralf Quint: Thanks for that. This is s typical example of one of those things that just don't make…
Ralf Quint wrote 16 lines
On 10/12/2015 10:18 AM, Michael Van Canneyt wrote: > > That is the meaning of "However, both syntax would cause code > incompatibility." > and is already in my very first reply to OP. > > So While... else or While .. Otherwise will never make it in the > compiler. Thanks for that. This is s typical example of one of those things that just don't make any sense in the first place. Either the while loop is executed or it isn't, depending in the expression. I don't see an actual use case for any else/otherwise extension to it...

The only possible use would be to specify a finalisation statement which was only executed if the while loop cycled at least once, or possibly one which was executed if the loop never cycled.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Steve Smith
to Dmitry Boyarintsev: You probably want to reread python while-else implementation. (…
Dmitry Boyarintsev wrote 49 lines
On Mon, Oct 12, 2015 at 1:35 PM, Ralf Quint < > wrote: Either the while loop is executed or it isn't, depending in the expression. I don't see an actual use case for any else/otherwise extension to it... You probably want to reread python while-else implementation. (https://docs.python.org/2/reference/compound_stmts.html) "Else" becomes sort of "part of the loop". Thus if you break out of the loop, "else" would not be executed. However, if no break occurs "else" part would be executed. It might be a rare case where it's needed. (I cannot think of any), but to achieve exactly the same functionality in Pascal either of two options should be used. 1) make an extra check if break occurred. breakflag:=false; while cond do if someothercond then begin breakflag : =true; break; end; if not breakflag then while_else_code 2) use goto! :) label postElseLabel while cond do if someothercond then begin goto postElseLabel end; while_else_code :postElseLabel thanks, Dmitry

I can't think of a use case either. And just because another language provides such a solution, does not imply that FPC should. As to achieving the functionality in FPC:

if cond then
   while cond do
     foo
else
   bar;

should suffice; Breakflags and gotos not required!

Reply by email

Sven Barth
to Dmitry Boyarintsev: Well, from fpc-devel list perspective your only hope is that any new feature is added via…

Am 12.10.2015 20:02 schrieb "Dmitry Boyarintsev" <

Show quoted text 5 lines
: On Mon, Oct 12, 2015 at 1:54 PM, Ralf Quint wrote: > > Sorry, we are programming here in Pascal, not Python. I could give a

rodent's posterior about what Python implements.

> > People need to properly design their software, not just hacking away.

Then they do not need to come up with whacko stop-gaps to fix what could have been done properly in the first place...

Well, from fpc-devel list perspective your only hope is that any new

feature is added via MODESWITCH. Thus any existing unit would be kept clean. You would also be able to keep your libraries clean, by not allowing using of a certain modeswitches.

Since one point of this discussion is to implement in a way that it doesn't break anything, it wouldn't be implemented.behind a modeswitch probably.

However, if you look at the recent (for the past few months) discussions,

you might spot that the number of requests for new features (from recent Delphi and other languages) is growing. Constantly.

True...

In this particular case it's even worse (actually it's better, from

fpc-devel POV), since the patch has been provided.

However we did nowhere state that we'd incorporate the feature. I only said that I'd definitely look at it to check whether the work in principle is good.

The next step would probably be controlled "break", where a user would be

able to specify how many nested loops needed to broken from.

That would be more useful than the while-else though :P

Regards,
Sven

Reply by email

Ralf Quint
to Sven Barth
Sven Barth wrote 43 lines
Am 12.10.2015 20:02 schrieb "Dmitry Boyarintsev" < >: > > On Mon, Oct 12, 2015 at 1:54 PM, Ralf Quint < > wrote: >> >> Sorry, we are programming here in Pascal, not Python. I could give a rodent's posterior about what Python implements. >> >> People need to properly design their software, not just hacking away. Then they do not need to come up with whacko stop-gaps to fix what could have been done properly in the first place... > > > Well, from fpc-devel list perspective your only hope is that any new feature is added via MODESWITCH. Thus any existing unit would be kept clean. You would also be able to keep your libraries clean, by not allowing using of a certain modeswitches. Since one point of this discussion is to implement in a way that it doesn't break anything, it wouldn't be implemented.behind a modeswitch probably. > However, if you look at the recent (for the past few months) discussions, you might spot that the number of requests for new features (from recent Delphi and other languages) is growing. Constantly. True... > In this particular case it's even worse (actually it's better, from fpc-devel POV), since the patch has been provided. However we did nowhere state that we'd incorporate the feature. I only said that I'd definitely look at it to check whether the work in principle is good. > The next step would probably be controlled "break", where a user would be able to specify how many nested loops needed to broken from. That would be more useful than the while-else though :P

Yes, I have seen a lot of those requests and pretty much none of them made any sense to me. As I already stated, it always seems to me that someone wants to have something implemented that they have seen in a different language, which might have a different approach to programming to begin with or they "think" they need a specific feature to get them out of a pickle they got themselves into because they are just hacking away instead of properly designing their programs. Neither of those case are IMHO valid to mess around with a working compiler. If someone is so fond of the features that Python/Haskell/Erland/<your favorite 'Cool-boy' programming language de jour> provides, then they should use that to solve their programming issues. They apparently don't understand how to use Pascal...

Ralf

---
This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Reply by email

DaWorm
to Mark Morgan Lloyd: The only possible use would be to specify a finalisation statement which was only…

I guess I'm confused. What is the difference between:

while true do this then that

and:

while true do this
that

And what is better about:

while true do this otherwise/else that

and:

if true
while true do this
else
that

The latter may have a difference if the thing that returns true for the "if" could be false by the time the "while" is executed, I suppose.

Jeff.

Reply by email

Unknown author
to Dmitry Boyarintsev: You probably want to reread python while-else implementation. (…
Dmitry Boyarintsev wrote 10 lines
On Mon, Oct 12, 2015 at 1:35 PM, Ralf Quint wrote: Either the while loop is executed or it isn't, depending in the expression. I don't see an actual use case for any else/otherwise extension to it... You probably want to reread python while-else implementation. (https://docs.python.org/2/reference/compound_stmts.html) "Else" becomes sort of "part of the loop". Thus if you break out of the loop, "else" would not be executed. However, if no break occurs "else" part would be executed.

that just doesn't make grammatical sense...

foo := 0;
while foo < 100 do
   inc(foo);
else
   dec(foo);
end

so, if foo is less than 100 we inc(foo)... if foo is not less than 100 we dec(foo)... that's the only way that an "else" can be read... either the boolean is true or /else/ it is false... only if it is false can the else portion be executed...

(#2) but then the question is does dec(foo) execute only once or does it execute as long as foo is greater than 100??

what i seem to see is pure laziness of a sort... folks too lazy to write an "if" or "if/else" statement and put the while inside...

foo := 0;
if foo < 100 then
   while foo < 100 do
     inc(foo);
else
   dec(foo);

OR depending on the answer of (#2) above...

foo := 0;
if foo < 100 then
   while foo < 100 do
     inc(foo);
   while foo > 100 do
     dec(foo);

or maybe this is the actual intent?

foo := 0;
if foo < 100 then
   while foo < 100 do
     inc(foo);
if foo > 100 then
   dec(foo);

seems like a pretty tough way to have foo equal to 99, eh? ;)

Show quoted text 5 lines
It might be a rare case where it's needed. (I cannot think of any), but to achieve exactly the same functionality in Pascal either of two options should be used. 1) make an extra check if break occurred.

[...]

2) use goto! :)

neither is needed at all in most cases and then not if they have proper logic in place ;)

NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list* unless private contact is specifically requested and granted.

Reply by email

Unknown author
to Dmitry Boyarintsev: Well, from fpc-devel list perspective your only hope is that any new feature is added via…
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? ;)

NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list* unless private contact is specifically requested and granted.

Reply by email

Dmitry Boyarintsev
to Unknown author
Show quoted text 15 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? ;)

How would you know if a nested loop finished properly or broke out? ...Just imagine yourself a 4 nested for loops and you need to break out from the 4th to the 1st?

thanks,
Dmitry

Reply by email

Unknown author
to Dmitry Boyarintsev
Dmitry Boyarintsev wrote 22 lines
On Mon, Oct 12, 2015 at 3:11 PM, < > wrote: 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? ;) How would you know if a nested loop finished properly or broke out? ...Just imagine yourself a 4 nested for loops and you need to break out from the 4th to the 1st?

by checking the value that caused the break ;) deity knows i've done it many times before back in the TP/BP 6&7 days... i did it exactly as described, too... we had to do it that way as there is/was no other way to do it ;)

NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list* unless private contact is specifically requested and granted.

Reply by email

Dmitry Boyarintsev
to Unknown author
by checking the value that caused the break ;) deity knows i've done it many times before back in the TP/BP 6&7 days... i did it exactly as described, too... we had to do it that way as there is/was no other way to do it ;)

That's exactly the thing. You didn't have a cross-loop break, that's why you've to have some guaranteed values that would allow you to verify if a loop was broken or not.

If it was broken then you'd set any additional conditions (if needed) to break out another loop and pass it above.

In the end you end-up having additional break condition checks in each loop. Just by the fact, that a language doesn't provide you with any other means to do it less complex.

I'd also need to note, that no other language, to my knowledge, have cross-loop breaks anyway :)
Good-old language (Pascal / C /C++) still have goto though... but we won't use it, right?

thanks,
Dmitry

Reply by email

Unknown author
to Dmitry Boyarintsev
Dmitry Boyarintsev wrote 11 lines
On Mon, Oct 12, 2015 at 3:47 PM, < > wrote: by checking the value that caused the break ;) deity knows i've done it many times before back in the TP/BP 6&7 days... i did it exactly as described, too... we had to do it that way as there is/was no other way to do it ;) That's exactly the thing. You didn't have a cross-loop break, that's why you've to have some guaranteed values that would allow you to verify if a loop was broken or not.

yeah... i implemented my needed logic for that type of scenario... just like any good programmer can/will/should do...

Show quoted text 6 lines
If it was broken then you'd set any additional conditions (if needed) to break out another loop and pass it above. In the end you end-up having additional break condition checks in each loop. Just by the fact, that a language doesn't provide you with any other means to do it less complex.

ok... so instead we'll have the compiler perform my business logic for me? no thanks... the compiler has enough to do already ;)

I'd also need to note, that no other language, to my knowledge, have cross-loop breaks anyway :) Good-old language (Pascal / C /C++) still have goto though... but we won't use it, right?

that's right... i think i may have used goto once in 30 years or however long it has been available in pascal... i started self-taught with basic... goto and gosub all over the place... tough as hades to follow the code and no apparent logical layout... i was ecstatic when a friend turned me on to pascal and asm... i dropped basic like a hot potato[e?] and never looked back... especially never looking back at goto ;) ;) ;)

NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list* unless private contact is specifically requested and granted.

Reply by email

David W Noon
to Unknown author: ROTFLMAO! if you need or desire something like that then set a breakcounter and break...…

-----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-----

Reply by email

David W Noon
to David W Noon

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, 12 Oct 2015 23:15:31 +0100, David W Noon
() wrote about "Re: [fpc-devel] Fwd: While
- - Otherwise Statement" (in ):

[snip]

IF some_condition THEH IF another_condition THEH IF some_other_condition THEH

These should all end in "THEN", not "THEH".
- --
Regards,

Dave [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAlYcM7sACgkQogYgcI4W/5SQagCfV6i2NrBee3h76kegPVARLq5V j7sAoNNPDGBtwsEWqdrrRiLylwoJkH7k
=ZVGL
-----END PGP SIGNATURE-----

Reply by email

Unknown author
to David W Noon: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Mon, 12 Oct 2015 15:11:18 -0400,…
David W Noon wrote 18 lines
On Mon, 12 Oct 2015 15:11:18 -0400, Wkitty42 () wrote about "Re: [fpc-devel] Fwd: While - Otherwise Statement" (in ): > 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,

hiya dave!! it has been a long time, my friend!!

You might have seen me write things like this in the old OS2PROG echo of Fidonet some 20+ years ago. ... :-)

oh yeah! that echo still exists, too... but it only contains monthly moderator postings these days... it is ready for you any time you want to join back in... nntp access is available via some systems but the dawg grows older with each passing year :?

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:

that looks very much like what some would consider goto statements... does the leave return to the top of the previous loop or does it drop to the next statement in the previous loop?

If the label is omitted then the immediately containing loop is left.

"immediately containing loop" meaning loop_3 if we're in loop_3?

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:

that does look interesting for breaks and i can see how it may be beneficial and save some bit of coding but then those of us who have been around a while know how to work our way back out when necessary, right? ;)

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.

yup! and i did catch the THEH->THEN oops... no problems there O:)

NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list* unless private contact is specifically requested and granted.

Reply by email

Flávio Etrusco
to David W Noon: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Mon, 12 Oct 2015 15:11:18 -0400,…
David W Noon wrote 29 lines
-----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 ): > 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. 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 I'm not missing something, Java implements 'break' just like this. I'd like such enhancement, but right now is there any reason to avoid 'goto' besides the bad karma?

Regards,
Flávio

Reply by email

Sven Barth
to Flávio Etrusco
"Flávio Etrusco" wrote 36 lines
On Mon, Oct 12, 2015 at 7:15 PM, David W Noon wrote: > -----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 > ): > >> 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. > > 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 I'm not missing something, Java implements 'break' just like this. I'd like such enhancement, but right now is there any reason to avoid 'goto' besides the bad karma?

The intrafunctional gotos not really. But the interfunctional ones (modeswitch nonlocalgoto in 2.7.1+) might mess with managed types ;)

Regards,
Sven

Reply by email

Jonas Maebe
to Sven Barth
Sven Barth wrote
The intrafunctional gotos not really. But the interfunctional ones (modeswitch nonlocalgoto in 2.7.1+) might mess with managed types ;)

The compiler should give an error if you try to "goto" out of or into a frame than needs initialisation/finalisation.

Jonas

Reply by email

Sven Barth
to Jonas Maebe
"Jonas Maebe" wrote 8 lines
Sven Barth wrote: > > The intrafunctional gotos not really. But the interfunctional ones > (modeswitch nonlocalgoto in 2.7.1+) might mess with managed types ;) The compiler should give an error if you try to "goto" out of or into a

frame than needs initialisation/finalisation.

Ah, ok, so we're already checking that. Good ^^
Then it's mostly the "bad karma" of goto I'd say ;)

Regards,
Sven

Reply by email

David W Noon
to Flávio Etrusco: On Mon, Oct 12, 2015 at 7:15 PM, David W Noon If I'm not missing something, Java…

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, 12 Oct 2015 22:34:03 -0300, Flávio Etrusco () wrote about "Re: [fpc-devel] Fwd: While -
Otherwise Statement" (in
):

On Mon, Oct 12, 2015 at 7:15 PM, David W Noon wrote:

[snip]

Show quoted text 5 lines
> loop_1: DO i = 1 TO m; loop_2 : DO j = 1 TO n; loop_3: DO k = 1 > TO p; ... IF some_condition THEN LEAVE loop_3;[...] If I'm not missing something, Java implements 'break' just like this.

Last time I coded any significant amount of Java it still used the C/C++ syntax -- but that was 10 or 11 years ago.

I'd like such enhancement, but right now is there any reason to avoid 'goto' besides the bad karma?

I view it largely as "the curse of Edsgar Dijkstra". A very short range goto should not be a real problem.
- --
Regards,

Dave [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAlYdI7gACgkQogYgcI4W/5QdGACgt7fbezm0wbDDASxjINbUI/tP rN0AnRSl7Ja7Sk3nIRGPqwQQUvAS0AqJ
=AQvj
-----END PGP SIGNATURE-----

Reply by email

David W Noon
to Unknown author: hiya dave!! it has been a long time, my friend!! oh yeah! that echo still exists, too...…

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, 12 Oct 2015 21:32:07 -0400, Wkitty42 ()
wrote about "Re: [fpc-devel] Fwd: While - Otherwise Statement" (in ):

[snip]

that looks very much like what some would consider goto statements... does the leave return to the top of the previous loop or does it drop to the next statement in the previous loop?

It leaves the loop at the END statement that matches the DO statement as labelled. So it goes to the next statement in the surrounding loop.

> If the label is omitted then the immediately containing loop is > left. "immediately containing loop" meaning loop_3 if we're in loop_3?

Correct. It's the same as break.

yup! and i did catch the THEH->THEN oops... no problems there O:)

Ageing eyes, I'm afraid. When I remove my contact lenses at night I have very distorted corneas (keratoconus) and cannot easily distinguish an H from an N. ... :-(
- --
Regards,

Dave [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAlYdJV4ACgkQogYgcI4W/5QZKgCaA7lhDyhW/D0E+ATdBhrkzyIM YrsAmwYelE+svkFxHDZvKLP3AJ/HZ8DN
=WNCc
-----END PGP SIGNATURE-----

Reply by email