May 24, 2003
"Matthew Wilson" <dmd@synesis.com.au> wrote in message news:b74p8g$35v$2@digitaldaemon.com...
> Being doing Python of late, and am impressed with some of the nice
features.
>
> One in particular I've always thought would be nice to have in C or C++ is for-else, as in
>
> for(int i = 0; i < 10; ++i)
> {
>     // do some stuff
>
> }
> else
> {
>     /// This only called if the for loop is terminated with a break
> statement.
> }
>
> Any takers for D?

How about:

for (int i = 0; i < 10; ++i)
{
    // do some stuff
    if (condition)
    {
        // This only executed if the for loop is terminated with a break
statement
        break;
    }
}


May 28, 2003
What if there are multiple breaks?

(I know, I know: local functions)


"Walter" <walter@digitalmars.com> wrote in message news:bampoi$10mn$2@digitaldaemon.com...
>
> "Matthew Wilson" <dmd@synesis.com.au> wrote in message news:b74p8g$35v$2@digitaldaemon.com...
> > Being doing Python of late, and am impressed with some of the nice
> features.
> >
> > One in particular I've always thought would be nice to have in C or C++
is
> > for-else, as in
> >
> > for(int i = 0; i < 10; ++i)
> > {
> >     // do some stuff
> >
> > }
> > else
> > {
> >     /// This only called if the for loop is terminated with a break
> > statement.
> > }
> >
> > Any takers for D?
>
> How about:
>
> for (int i = 0; i < 10; ++i)
> {
>     // do some stuff
>     if (condition)
>     {
>         // This only executed if the for loop is terminated with a break
> statement
>         break;
>     }
> }
>
>


June 06, 2003
You can use:
    break label;

"Matthew Wilson" <matthew@stlsoft.org> wrote in message news:bb1gip$2j6s$1@digitaldaemon.com...
> What if there are multiple breaks?
>
> (I know, I know: local functions)
>
>
> "Walter" <walter@digitalmars.com> wrote in message news:bampoi$10mn$2@digitaldaemon.com...
> >
> > "Matthew Wilson" <dmd@synesis.com.au> wrote in message news:b74p8g$35v$2@digitaldaemon.com...
> > > Being doing Python of late, and am impressed with some of the nice
> > features.
> > >
> > > One in particular I've always thought would be nice to have in C or
C++
> is
> > > for-else, as in
> > >
> > > for(int i = 0; i < 10; ++i)
> > > {
> > >     // do some stuff
> > >
> > > }
> > > else
> > > {
> > >     /// This only called if the for loop is terminated with a break
> > > statement.
> > > }
> > >
> > > Any takers for D?
> >
> > How about:
> >
> > for (int i = 0; i < 10; ++i)
> > {
> >     // do some stuff
> >     if (condition)
> >     {
> >         // This only executed if the for loop is terminated with a break
> > statement
> >         break;
> >     }
> > }
> >
> >
>
>


1 2
Next ›   Last »