May 24, 2003 Re: Python inspirations | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Matthew Wilson | "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 Re: Python inspirations | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter | 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 Re: Python inspirations | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Matthew Wilson | 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;
> > }
> > }
> >
> >
>
>
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply