http://d.puremagic.com/issues/show_bug.cgi?id=6550

           Summary: Allow (auto var = expression) in while() loops
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: andrej.mitrov...@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrov...@gmail.com> 2011-08-24 
12:42:26 PDT ---
Currently this doesn't compile:

   while (auto parent = foo.parent)
   {
       foo = parent;
   }

Error: expression expected, not 'auto'

This is useful to replace this kind of loop (assume foo is a class object that
has a 'parent' field):

   while (true)
   {
       if (auto parent = foo.parent)
       {
           // do something with parent
           foo = parent;  // switch to next parent
       }
       else
       {
           break;
       }
   }

with the simpler:

   while (auto parent = foo.parent)
   {
       // do something with parent
       foo = parent;  // switch to next parent
   }

Currently `if` statements already allow this syntax, so it seems natural to
extend this to `while` loops.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to