Why use while if only iterating once ?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sat Nov 3 21:13:49 UTC 2018


On Saturday, November 3, 2018 3:03:16 PM MDT Venkat via Digitalmars-d-learn 
wrote:
>          while (1)
>          {
>              FLAGS f;
>              switch (*p)
>              {
>              case 'U':
>              case 'u':
>                  f = FLAGS.unsigned;
>                  goto L1;
>              case 'l':
>                  f = FLAGS.long_;
>                  error("lower case integer suffix 'l' is not
> allowed. Please use 'L' instead");
>                  goto L1;
>              case 'L':
>                  f = FLAGS.long_;
>              L1:
>                  p++;
>                  if ((flags & f) && !err)
>                  {
>                      error("unrecognized token");
>                      err = true;
>                  }
>                  flags = cast(FLAGS)(flags | f);
>                  continue;
>              default:
>                  break;
>              }
>              break;
> }
>
>
> The last break statement prevents the loop from returned for a
> second iteration. Then why use a while ?

There's a continue right above the default case. So, if the code hits that
point, it will loop back to the top.

- Jonathan M Davis





More information about the Digitalmars-d-learn mailing list