Topic: Use of break keyword


Author: David R Tribble <david@tribble.com>
Date: Fri, 2 Mar 2001 18:39:31 GMT
Raw View
Danny Kelly wrote:
> I have had the idea of having the break statement OPTIONALLY have a
> number after it indicating the number of loops to break from. If no
> number is there, it is assumed to be just like using 1, meaning break
> out of 1 loop.
>
> for (int i = 0; i < s; i++)
> {
>     //a whole bunch of stuff
>
>     for (int j = 0; j < q; j++)
>     {
>         //more stuff
>
>         if (i want to get out of both loops)
>         {
>             //maybe some stuff
>             break 2;
>         }
>     }
> }
>
> What do you think about it?

If we are going to add something like this to C++, I would prefer
that we use the existing syntax of Java:

  loop:                                 // labeled loop statement
    for (int i = 0; i < s; i++)
    {
        // a whole bunch of stuff
        for (int j = 0; j < q; j++)
        {
            // more stuff
            if (i want to get out of both loops)
            {
                // maybe some stuff
                break loop;             // new feature
            }
        }
    }

Basically, a 'break' or 'continue' can be followed by an optional
label name, which specifies the label of the loop statement to break
out of or to continue.

Of course, Java doesn't have 'goto', so it had to add some syntactic
feature to allow this sort of thing.  C++ does have 'goto', though,
so the same thing can already be done using 'goto', albeit in a way
that is not quite as visually pleasing:

  i_loop:
    for (int i = 0; i < s; i++)
    {
        // some stuff
        for (int j = 0; j < q; j++)
        {
            // more stuff
            if (I want to get out of both loops)
                goto after_loop;   // equiv. to 'break i_loop;'
            if (I want to skip the rest of the i-loop)
                goto i_again;      // equiv. to 'continue i_loop;'
            // more stuff
        }
        // more stuff
    i_again: ;
    }
  after_loop: ;

The fact that C++ already has a way of doing this makes it unlikely
that a new syntactic feature will be added.  The principle is to
keep the language and library as small as possible (as incredible
as this might sound, given the complexity of both); if C++ gives you
a fairly obvious and simple way to do something already, the
committee will more than likely say "just use the existing way".

(Apologies if this has all been brought up before.)

--
David R. Tribble, mailto:david@tribble.com, http://david.tribble.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: Daniel Frey <daniel.frey@aixigo.de>
Date: Tue, 20 Feb 2001 19:16:07 GMT
Raw View
Danny Kelly wrote:
>=20
> Something that really sucks is when you got a couple of nested for loop=
s
> and you want to get out of both of them instead of just the current one=
,
> which is what the break keyword does.
>=20
> Everything gets much more complicated if you try to do this without a
> goto, especially if the loops happened to be complicated in the first
> place.
>=20
> I have had the idea of having the break statement OPTIONALLY have a
> number after it indicating the number of loops to break from. If no
> number is there, it is assumed to be just like using 1, meaning break
> out of 1 loop.

Can I use a variable ( 'break i;' )? Or do I have to use a
compile-time-constant expression? ;)

> for (int i =3D 0; i < s; i++)
> {
>     //a whole bunch of stuff
>=20
>     for (int j =3D 0; j < q; j++)
>     {
>         //more stuff
>=20
>         if (i want to get out of both loops)
>         {
>             //maybe some stuff
>             break 2;
>         }
>     }
> }
>=20
> What do you think about it?

It think it is a good idea because when such a problem occurs, the loops
are usually long enough to make the code unreadable. If anything like
that should be allowed, I would prefer something like named loops:

for( int i =3D 0; i < s; ++i ) My1stIterator // <-- the identifier for
this loop (don't ask me for the type :)
{
   for( int j =3D 0; j < q; ++j ) // an unnamed loop
   {
      if( foo =3D=3D bar ) {
         // ...
         break My1stIterator;
      }
   }
}

Regards, Daniel

--
Daniel Frey

aixigo AG - financial training, research and technology
Schlo=DF-Rahe-Stra=DFe 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey@aixigo.de, web: http://www.aixigo.de

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: Ron Natalie <ron@spamcop.net>
Date: Tue, 20 Feb 2001 19:24:00 GMT
Raw View

Daniel Frey wrote:
>
> for( int i = 0; i < s; ++i ) My1stIterator // <-- the identifier for
> this loop (don't ask me for the type :)
> {
>    for( int j = 0; j < q; ++j ) // an unnamed loop
>    {
>       if( foo == bar ) {
>          // ...
>          break My1stIterator;
>       }
>    }
> }
>
It already exists.

 for(int i = 0; i < s; ++i) {
    unidentified_loop {
      for(int j = 0; j < q; ++j) {
  if(foo == bar)  {
    goto after_outer_loop;
  }
      }
 }
 after_outer_loop: ;

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: Daniel Frey <d.frey@gmx.de>
Date: Tue, 20 Feb 2001 21:12:42 GMT
Raw View
Ron Natalie wrote:

>
> Daniel Frey wrote:
>
>> for( int i = 0; i < s; ++i ) My1stIterator // <-- the identifier for
>> this loop (don't ask me for the type :)
>> {
>>    for( int j = 0; j < q; ++j ) // an unnamed loop
>>    {
>>       if( foo == bar ) {
>>          // ...
>>          break My1stIterator;
>>       }
>>    }
>> }
>>
>
> It already exists.
>
>  for(int i = 0; i < s; ++i) {
>     unidentified_loop {
>       for(int j = 0; j < q; ++j) {
>   if(foo == bar)  {
>     goto after_outer_loop;
>   }
>       }
>  }
>  after_outer_loop: ;

That's not the same. The label is placed *after* the loop and it is independent.
This is a small but important difference. But I won't recommend something like
named loops anyway, I would just prefer it over something like 'break 2;'. IMHO
there is no need for something like that, we can live without it.

Just my $0.02

Regards, Daniel

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: Danny Kelly <fsmmu.lrlly@home.com>
Date: Tue, 20 Feb 2001 21:25:44 GMT
Raw View

Ron Natalie wrote:
>
> Danny Kelly wrote:
> >
> > Something that really sucks is when you got a couple of nested for loops
> > and you want to get out of both of them instead of just the current one,
> > which is what the break keyword does.
>
> "goto" is clearer than "break to the n-th power"

goto is not clearer because you have to find where the identifier to
goto is in the code. the new break statement makes it perfectly clear
that you are exiting out of x loops:

break 2;

> >
> > Everything gets much more complicated if you try to do this without a
> > goto, especially if the loops happened to be complicated in the first
> > place.
>
> It's complicated no matter how you do it, you're really breaking the idea
> of structured code doing this.
>
> >
> > I have had the idea of having the break statement OPTIONALLY have a
> > number after it indicating the number of loops to break from.
>
> You aren't the first, but it's a bad idea.  It's worse than goto.
> If you have to violate structure, you might as well be explicit about it.

It is NOT worse than goto! The bad thing about goto was not "breaking
the structure", it was making the code CONFUSING, and hard to comprehend
and follow. Using the new break statement makes the source code writer's
intention MUCH CLEARER.

>
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
> [ Note that the FAQ URL has changed!  Please update your bookmarks.     ]


======================================= MODERATOR'S COMMENT:
 Please don't overquote.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: Pete Becker <petebecker@acm.org>
Date: Wed, 21 Feb 2001 00:02:36 GMT
Raw View
Danny Kelly wrote:
>
> Ron Natalie wrote:
> >
> > Danny Kelly wrote:
> > >
> > > Something that really sucks is when you got a couple of nested for loops
> > > and you want to get out of both of them instead of just the current one,
> > > which is what the break keyword does.
> >
> > "goto" is clearer than "break to the n-th power"
>
> goto is not clearer because you have to find where the identifier to
> goto is in the code. the new break statement makes it perfectly clear
> that you are exiting out of x loops:

which you then have to find. Besides, break is used for more than
exiting loops.

>
> It is NOT worse than goto! The bad thing about goto was not "breaking
> the structure", it was making the code CONFUSING, and hard to comprehend
> and follow. Using the new break statement makes the source code writer's
> intention MUCH CLEARER.

It may well make the intention clearer, but it makes the code more
difficult to follow and more fragile. More difficult to follow because
the target of the bogus break depends on the context where it occurs.
More fragile because with this construct, when you change the code you
have to look at all the break statements to be sure you haven't
accidentally changed their meanings.

--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: "Stephen Howe" <NOSPAMsjhowe@dial.pipex.co.uk>
Date: Wed, 21 Feb 2001 14:04:54 GMT
Raw View
"Danny Kelly" <fsmmu.lrlly@home.com> wrote in message
news:3A92E158.EA799FC5@home.com...
>
>
> Ron Natalie wrote:
> >
> > Danny Kelly wrote:
> > >
> > > Something that really sucks is when you got a couple of nested for
loops
> > > and you want to get out of both of them instead of just the current
one,
> > > which is what the break keyword does.
> >
> > "goto" is clearer than "break to the n-th power"
>
> goto is not clearer because you have to find where the identifier to
> goto is in the code. the new break statement makes it perfectly clear
> that you are exiting out of x loops:
>
> break 2;

Goto is cleaner. Consider the following

for (int j =0; j < 100; ++j)
{   for (int k = j; k < 100; ++k)
    {
        :
        if (condition)
            break 2;
    }
}


Now suppose, later on, we have to wrap another loop around this. All the
break n's have to be adjusted to work as they did before. For large loops
and many modules this is error prone. I would not want to maintain this
code. In contrast, if he goto label is just outside the outer for loop, it
needs no adjustment to continue to work, it just does.

Stephen Howe


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: "Andrew F. Vesper" <andy.vesper@acm.org>
Date: Wed, 21 Feb 2001 17:26:05 GMT
Raw View
Daniel Frey wrote:

> That's not the same. The label is placed *after* the loop and it is independent.

Well, if you just want the label at the top of the loop:

if (0) {
exitouterloop: ;
}
else for (int outer = 0; outer < OUTER_LIMIT; ++outer)
{
    for (int inner = 0; inner < INNER_LIMIT; ++inner)
    {
        if (outer > inner) goto exitouterloop;
    }
}


> This is a small but important difference. But I won't recommend something like
> named loops anyway, I would just prefer it over something like 'break 2;'. IMHO
> there is no need for something like that, we can live without it.

Named loops are better than numbered ones, but only in the sense
that Windows 98 is better than Windows 95.
:-)
:-(

--
Andy V (OpenGL Alpha Geek)
"In order to make progress, one must leave the door to the unknown ajar."
Richard P. Feynman, quoted by Jagdish Mehra in _The Beat of a Different Drum_.


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: "Victor Bazarov" <vAbazarov@dAnai.com>
Date: Wed, 21 Feb 2001 19:51:26 GMT
Raw View
"Danny Kelly" <fsmmu.lrlly@home.com> wrote...
>
>
> Ron Natalie wrote:
> >
> > Danny Kelly wrote:
> > >
> > > Something that really sucks is when you got a couple of nested for
loops
> > > and you want to get out of both of them instead of just the
current one,
> > > which is what the break keyword does.
> >
> > "goto" is clearer than "break to the n-th power"
>
> goto is not clearer because you have to find where the identifier to
> goto is in the code. the new break statement makes it perfectly clear
> that you are exiting out of x loops:
>
> break 2;
>
> > >
> > > Everything gets much more complicated if you try to do this
without a
> > > goto, especially if the loops happened to be complicated in the
first
> > > place.
> >
> > It's complicated no matter how you do it, you're really breaking the
idea
> > of structured code doing this.
> >
> > >
> > > I have had the idea of having the break statement OPTIONALLY have
a
> > > number after it indicating the number of loops to break from.
> >
> > You aren't the first, but it's a bad idea.  It's worse than goto.
> > If you have to violate structure, you might as well be explicit
about it.
>
> It is NOT worse than goto! The bad thing about goto was not "breaking
> the structure", it was making the code CONFUSING, and hard to
comprehend
> and follow. Using the new break statement makes the source code
writer's
> intention MUCH CLEARER.

... and the code much more difficult to maintain.

Imagine that the code that is now

    for (blah)
    {
        for (blahblah)
        {
            ...
            break 2;
        }
    }

has to be corrected as following (whatever reason):

    for (blah)
    {
        for (blah_and_a_half) // new
        {                     // new
        for (blahblah)
        {
            ...
            break 2;
        }
        }                     //  new
    }

There would be no change required had there been a goto "outside"
statement.  In the current situation, I have to correct all break
"greater_than_1" statements.

So, the "break with a number"'s being worse than goto is relative.

Victor
--
Please remove capital A's from my address when replying by mail



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: Daniel Frey <daniel.frey@aixigo.de>
Date: Wed, 21 Feb 2001 19:51:36 GMT
Raw View
"Andrew F. Vesper" wrote:
>=20
> Daniel Frey wrote:
>=20
> > That's not the same. The label is placed *after* the loop and it is i=
ndependent.
>=20
> Well, if you just want the label at the top of the loop:
>=20
> if (0) {
> exitouterloop: ;
> }
> else for (int outer =3D 0; outer < OUTER_LIMIT; ++outer)
> {
>     for (int inner =3D 0; inner < INNER_LIMIT; ++inner)
>     {
>         if (outer > inner) goto exitouterloop;
>     }
> }

Hm, we could create macros for that:

#define breakable_loop(label) if(false){label:;}else
#define break_loop(label) do{goto label;}while(true)

so you can write

breakable_loop( My1stLoop ) for (int outer =3D 0; outer < OUTER_LIMIT;
++outer)
{
  for (int inner =3D 0; inner < INNER_LIMIT; ++inner)
  {
    if (outer > inner) break_loop( My1stLoop );
  }
}

...this is becoming increasingly pervert...

> Named loops are better than numbered ones, but only in the sense
> that Windows 98 is better than Windows 95.
> :-)

The above macros should therefore reside in a header called
<windoz2k.h>, right? O:)

Best regards, Daniel

--
Daniel Frey

aixigo AG - financial training, research and technology
Schlo=DF-Rahe-Stra=DFe 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey@aixigo.de, web: http://www.aixigo.de

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: Ron Natalie <ron@spamcop.net>
Date: Wed, 21 Feb 2001 19:51:31 GMT
Raw View

Danny Kelly wrote:
>
> Ron Natalie wrote:
> >
> > Danny Kelly wrote:
> > >
> > > Something that really sucks is when you got a couple of nested for loops
> > > and you want to get out of both of them instead of just the current one,
> > > which is what the break keyword does.
> >
> > "goto" is clearer than "break to the n-th power"
>
> goto is not clearer because you have to find where the identifier to
> goto is in the code. the new break statement makes it perfectly clear
> that you are exiting out of x loops:
>
> break 2;

This is clearer?  You have to find the two loops it's breaking out of and
find the next statement following?  Every indentation level isn't necessarily
a loop, it's clearer to have a label saying ... THIS HIDDEOUS UNSTRUCTURED
JUMP IS GOING TO GO HERE.

> It is NOT worse than goto! The bad thing about goto was not "breaking
> the structure", it was making the code CONFUSING,

No, the bad thing about GOTO is it lead to incredibly non structured
constructs.  Do you even know what structured programming is?  If you
previos use of GOTO was limitted to performing structured control flow,
it wouldn't have the stigma it does.

> Using the new break statement makes the source code writer's
> intention MUCH CLEARER.

No, it makes it much less clear.  Jumping out an arbitrary number
of loops (especially if not a numeric literal is not used) is incredibly
confusing, and a violation of structured programming.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: Danny Kelly <fsmmu.lrlly@home.com>
Date: Wed, 21 Feb 2001 23:12:34 GMT
Raw View

Ron Natalie wrote:
>
> Danny Kelly wrote:
> >
> > Ron Natalie wrote:
> > >
> > > Danny Kelly wrote:
> > > >
> > > > Something that really sucks is when you got a couple of nested for loops
> > > > and you want to get out of both of them instead of just the current one,
> > > > which is what the break keyword does.
> > >
> > > "goto" is clearer than "break to the n-th power"
> >
> > goto is not clearer because you have to find where the identifier to
> > goto is in the code. the new break statement makes it perfectly clear
> > that you are exiting out of x loops:
> >
> > break 2;
>
> This is clearer?  You have to find the two loops it's breaking out of and
> find the next statement following?  Every indentation level isn't necessarily
> a loop, it's clearer to have a label saying ... THIS HIDDEOUS UNSTRUCTURED
> JUMP IS GOING TO GO HERE.
>
> > It is NOT worse than goto! The bad thing about goto was not "breaking
> > the structure", it was making the code CONFUSING,
>
> No, the bad thing about GOTO is it lead to incredibly non structured
> constructs.  Do you even know what structured programming is?  If you
> previos use of GOTO was limitted to performing structured control flow,
> it wouldn't have the stigma it does.
>

"incredibly non structured constructs" were bad BECAUSE they made code
CONFUSING and HARD TO MAINTAIN!!


> > Using the new break statement makes the source code writer's
> > intention MUCH CLEARER.
>
> No, it makes it much less clear.  Jumping out an arbitrary number
> of loops (especially if not a numeric literal is not used) is incredibly
> confusing, and a violation of structured programming.
>
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
> [ Note that the FAQ URL has changed!  Please update your bookmarks.     ]

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: Danny Kelly <fsmmu.lrlly@home.com>
Date: Mon, 19 Feb 2001 17:03:07 GMT
Raw View
Something that really sucks is when you got a couple of nested for loops
and you want to get out of both of them instead of just the current one,
which is what the break keyword does.

Everything gets much more complicated if you try to do this without a
goto, especially if the loops happened to be complicated in the first
place.

I have had the idea of having the break statement OPTIONALLY have a
number after it indicating the number of loops to break from. If no
number is there, it is assumed to be just like using 1, meaning break
out of 1 loop.

for (int i = 0; i < s; i++)
{
    //a whole bunch of stuff

    for (int j = 0; j < q; j++)
    {
        //more stuff

        if (i want to get out of both loops)
        {
            //maybe some stuff
            break 2;
        }
    }
}

What do you think about it?

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: Ron Natalie <ron@spamcop.net>
Date: Mon, 19 Feb 2001 18:31:28 GMT
Raw View

Danny Kelly wrote:
>
> Something that really sucks is when you got a couple of nested for loops
> and you want to get out of both of them instead of just the current one,
> which is what the break keyword does.

"goto" is clearer than "break to the n-th power"
>
> Everything gets much more complicated if you try to do this without a
> goto, especially if the loops happened to be complicated in the first
> place.

It's complicated no matter how you do it, you're really breaking the idea
of structured code doing this.

>
> I have had the idea of having the break statement OPTIONALLY have a
> number after it indicating the number of loops to break from.

You aren't the first, but it's a bad idea.  It's worse than goto.
If you have to violate structure, you might as well be explicit about it.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Mon, 19 Feb 2001 23:45:14 GMT
Raw View
In article <3A904C5E.6CE7048C@home.com>, Danny Kelly
<fsmmu.lrlly@home.com> writes
>for (int i = 0; i < s; i++)
>{
>    //a whole bunch of stuff
>
>    for (int j = 0; j < q; j++)
>    {
>        //more stuff
>
>        if (i want to get out of both loops)
>        {
>            //maybe some stuff
>            break 2;
>        }
>    }
>}
>
>What do you think about it?

bool nested(int i){
        for (int j = 0; j < q; ++j){
                // do whatever
                if(test) return false;
        }
        return true;
}

void outer(){
        for(int i=0; i<s; ++i){
                if(!nested(i)) break;
        }
}

Yes, I know that it is more complicated in reality but the above is just
an outline, to demonstrate that you do not need goto, or some other
mechanism to achieve your intent.


--
Francis Glassborow
See http://www.accu.org for details of The ACCU Spring Conference, 2001
(includes many regular participants to C & C++ newsgroups)

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: "Greg Brewer" <nospam.greg@brewer.net>
Date: Tue, 20 Feb 2001 14:42:58 GMT
Raw View
I think it is a great feature to have.  I programmed in the Rexx programming
language -- which has the syntax -- about 10 years ago and it really
cleanned up the coding in some complicated situations.

I'm thinking a similar change might be useful to the continue statement.

Greg


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]