From: Richard Heathfield on
Juha Nieminen wrote:
> In comp.lang.c++ spinoza1111 <spinoza1111(a)yahoo.com> wrote:
>> On Apr 25, 1:09 pm, Juha Nieminen <nos...(a)thanks.invalid> wrote:
>>> In comp.lang.c++ Ali Karaali <ali...(a)gmail.com> wrote:
>>>
>>>> I use goto to break nested for loops and I can't see a
>>>> reason to ban goto.
>>> No. The correct keyword for breaking out of nested loops (in C++) is
>>> 'return'. If you are using 'goto' for that purpose, you are doing it
>>> wrong.
>> Don't you mean "break"?
>
> Exactly how do you exit out of a set of nested loops with a "break"?

I don't. I exit out of a set of nested loops using the conditions in the
loop controllers.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within
From: Juha Nieminen on
In comp.lang.c++ Richard Heathfield <rjh(a)see.sig.invalid> wrote:
>> Exactly how do you exit out of a set of nested loops with a "break"?
>
> I don't. I exit out of a set of nested loops using the conditions in the
> loop controllers.

The idea was to make the code simpler, cleaner and easier to follow, not
more complicated and contrived.
From: Richard Heathfield on
Juha Nieminen wrote:
> In comp.lang.c++ Richard Heathfield <rjh(a)see.sig.invalid> wrote:
>>> Exactly how do you exit out of a set of nested loops with a "break"?
>> I don't. I exit out of a set of nested loops using the conditions in the
>> loop controllers.
>
> The idea was to make the code simpler, cleaner and easier to follow, not
> more complicated and contrived.

Yes. That's precisely why I use the conditions in the loop controllers.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within
From: Juha Nieminen on
In comp.lang.c++ Richard Heathfield <rjh(a)see.sig.invalid> wrote:
> Juha Nieminen wrote:
>> In comp.lang.c++ Richard Heathfield <rjh(a)see.sig.invalid> wrote:
>>>> Exactly how do you exit out of a set of nested loops with a "break"?
>>> I don't. I exit out of a set of nested loops using the conditions in the
>>> loop controllers.
>>
>> The idea was to make the code simpler, cleaner and easier to follow, not
>> more complicated and contrived.
>
> Yes. That's precisely why I use the conditions in the loop controllers.

Care to show an actual example of your "simpler, cleaner and easier to
follow" version of exiting a nested loop by meddling with the loop
conditions instead of using 'return'? For example, modify the following
code to conform to your specifications:

Value_t* MyClass::findValue(const Value_t& value)
{
for(size_t xInd = 0; xInd < data.size(); ++xInd)
for(size_t yInd = 0; yInd < data[xInd].size(); ++yInd)
for(size_t zInd = 0; zInd < data[xInd][yInd].size(); ++zInd)
{
if(data[xInd][yInd][zInd] == value)
return &data[xInd][yInd][zInd];
}

return 0;
}
From: tonydee on
On Apr 25, 7:47 am, James Kanze <james.ka...(a)gmail.com> wrote:
> [...] in C and in
> C++, for all "good" uses of goto (and a number of bad ones), the
> language has specialized structures which better express the
> meaning.

Just not so. Much low-level state-based code is best expressed via
gotos. There are a couple hundred usages spread over 7 different
Boost libraries (as of 1.41). Have a look and you might find
something you think reasonable. Sometimes working too much in a
particular set of problem domains can either make it seem like goto
isn't beneficial, or make it completely obvious it is. Parsers are
one area where the uses are clear, for example: the boost regex
parser. Similarly, some lexers I've written have employed gotos
too... it's just cleaner. I'm pretty sure Walter Bright chipped in on
an argument like this a couple years back, also supporting some uses
of gotos... not somebody who's experience I'd challenge - will try to
dig up the reference if anyone cares....

Cheers,
Tony