Proposal of a general do-while loop
Joe Gottman
jgottman at carolina.rr.com
Tue Jul 17 16:40:32 PDT 2007
Taro Kawagishi wrote:
>
> I think a more natural way to express the logic is to write the code as in listing 4.
>
> // listing 4
> size_t pos = 0;
> do {
> pos = text.find(pattern, pos);
> } while (pos != string::npos) {
> cout << "pattern found at " << pos << "\n";
> ++pos;
> }
>
> The meaning of
>
> do {
> aa;
> } while (bb) {
> cc;
> }
>
> is
>
> while (true) {
> aa;
> if (not bb) {
> break;
> }
> cc;
> }
>
> and is a natural extension to both of
>
> do {
> aa;
> } while (bb);
>
> and
>
> while (bb) {
> cc;
> }
>
This looks very nice. Does this mean that the entire construct is
one scope, so that a variable declared in the aa section is accessible
in the bb and cc sections and a variable declared in the bb section is
accessible in the cc section?
Joe Gottman
More information about the Digitalmars-d
mailing list