No more fall through in case statement?
Leonard Dahlmann
leo.dahlmann at gmail.com
Thu Jan 3 10:57:57 PST 2008
bearophile Wrote:
> bearophile:
>
> > caseof (s[i]) {
> > case ' ': fall;
> > case '\t': fall;
> > case '\f': fall;
> > case '\r': fall;
> > case '\n': fall;
> > case '\v':
> > if (inword) {
> > r ~= capitalize(s[istart .. i]);
> > inword = false;
> > }
> >
> > default:
> > if (!inword) {
> > if (r.length)
> > r ~= ' ';
> > istart = i;
> > inword = true;
> > }
> > }
>
> Let's try again, 2 keywords less:
>
> caseof (s[i]) {
> case ' ': continue;
> case '\t': continue;
> case '\f': continue;
> case '\r': continue;
> case '\n': continue;
> case '\v':
> if (inword) {
> r ~= capitalize(s[istart .. i]);
> inword = false;
> }
>
> else:
> if (!inword) {
> if (r.length)
> r ~= ' ';
> istart = i;
> inword = true;
> }
> }
>
> :-)
>
> Bye,
> bearophile
I doubt that 'continue' can be used there - what if we have a caseof in a loop?
foreach(x; y)
{
caseof(s[i])
{
case '': continue; // fallthrough or continue the loop?
}
}
One could workaround this by giving the loop a label and using it
with 'continue', but still, this might be confusing for beginners.
More information about the Digitalmars-d
mailing list