www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6550] New: Allow (auto var = expression) in while() loops

reply d-bugmail puremagic.com writes:
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: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com



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: -------
Aug 24 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6550


timon.gehr gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr gmx.ch



note that this can be implemented with a simple rewrite rule.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 24 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6550


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies gmail.com
         Resolution|                            |DUPLICATE



*** This issue has been marked as a duplicate of issue 5432 ***

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