From: Nick on
"Daniel T." <daniel_t(a)earthlink.net> writes:

> There is a general pattern here I think. When there are multiple exit
> conditions to a loop (there is an && in the exit condition,) and we have
> to be able to distinguish after the loop which condition caused it to
> exit, then it may be appropriate to have multiple exits from the loop.
> I'm just musing here, but what do you guys think?

I'm very happy with it. My view is that leaving early is perfectly all
right in at least two circumstances:
a) in a "do I do this at all?" check at the start of some code
b) when you've finished what you came to do (like finding something in a
search function).

For (a), I'd much rather see
enum retval do_something(char *s) {
if(s == NULL)
return no_string;
if(!*s)
return empty_string;
if(strlen(s) < 3)
return short_string;
while(*s) {
if(....)
}
return not_found;
}

than something involving a pile of nested ifs and a variable to hold the
eventual return value. This way you *know* that all's over with,
without reading down to the bottom to check.
--
Online waterways route planner | http://canalplan.eu
Plan trips, see photos, check facilities | http://canalplan.org.uk
From: robin on
"James Van Buskirk" <not_valid(a)comcast.net> wrote in message news:hr1q1g$h5v$1(a)news.eternal-september.org...
| "Alexei A. Frounze" <alexfrunews(a)gmail.com> wrote in message
| news:aab23e01-b4d4-44c4-a136-a619da00a3f7(a)m24g2000prc.googlegroups.com...
|
| > I wish there were distinct breaks for loops and switches as well as
| > multi-level breaks for nested loops. goto's at times are the least
| > evil since they don't require you to implement extra variables to
| > break out of nested loops and they help to simplify function cleanup
| > code (where resources are being freed on various conditions).
|
| Amusing that Fortran has a mechanism to break out of nested loops
| and permits one to use internal subroutines for function cleanup,
| not to mention no fall-through in SELECT CASE constructs.

Thank goodness.

| These uses
| of goto are simply artifacts of the limitations of C-style languages.


From: James Kanze on
On Apr 25, 12:17 pm, Phil Carmody <thefatphil_demun...(a)yahoo.co.uk>
wrote:
> James Kanze <james.ka...(a)gmail.com> writes:
> > On Apr 24, 1:20 pm, "Leigh Johnston" <le...(a)i42.co.uk> wrote:
> >> "spinoza1111" <spinoza1...(a)yahoo.com> wrote in message

[...]
> >> Because break only breaks out of the innermost loop, using
> >> goto to break out of nested loops is one of the few sensible
> >> uses of goto.

> > But when do you have to break out of a nested loop?

> For the same reason you want to break out of a single loop.
> Do you have issues with people breaking out of single loops?

I've never really seen a case where it was appropriate (if by
"breaking out", you mean using the break statement to obfuscate
the code by hiding the actual program flow).

> > (And of course, the only valid use of break in C++ is to end
> > a case in a switch. Otherwise, it's just a goto in
> > disguise.)

> What do you mean by 'otherwise' - even that's just a goto in
> disguise?

Yes, because switch is fairly broken. On the other hand, the
language doesn't provide anything better. One of the most
structured programs I ever saw was full of goto's. Because it
was written in Fortran IV, and the language didn't provide any
of the necessary structures natively. In the case of C/C++,
about the only useful flow control structure that isn't provided
natively is a true switch or case statement, so we have to use
the one provided.

--
James Kanze
From: Frank Kotler on
io_x wrote:

....
> --------------------
> yes "je .1" would it mean "if zero flag == 1 goto .1";
> "je" is a 'conditional' goto;
> jmp is a goto.

Whereas "break", in my world, is an "OS thing" and has to do with
memory, not flow-control. I wanna use 'em both!

Best,
Frank
From: io_x on
"Frank Kotler" ha scritto nel messaggio:
> io_x wrote:
>
> ...
>> --------------------
>> yes "je .1" would it mean "if zero flag == 1 goto .1";
>> "je" is a 'conditional' goto;
>> jmp is a goto.
>
> Whereas "break", in my world, is an "OS thing" and has to do with memory, not
> flow-control. I wanna use 'em both!

yes i use in asm "je" and "jmp" [or their macro] both; but even
"jmp .2" can be seen as a conditional goto too: "if 1 goto .2"?
so Theorem: all gotos are 'conditional' gotos.

i use "break" only in C/C++ because these language are understood
in that way

> Best,
> Frank