Thread overview
[Issue 4131] New: break does not work correctly with foreach and associative arrays
Apr 27, 2010
Sönke Ludwig
Apr 28, 2010
Don
Apr 30, 2010
Walter Bright
May 06, 2010
Don
April 27, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4131

           Summary: break does not work correctly with foreach and
                    associative arrays
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: ludwig@informatik.uni-luebeck.de


--- Comment #0 from Sönke Ludwig <ludwig@informatik.uni-luebeck.de> 2010-04-27 15:01:57 PDT ---
Issuing a break statement will not cause the foreach loop to exit but instead will perform another iteration before jumping out.

---
import std.stdio;

void main()
{
    int[int] test;
    test[0] = 0;
    test[1] = 1;

    bool flag = false;
    foreach( k, v; test){
        writefln("loop: %s %s", k, v);
        assert(!flag); // fails on second loop!
        flag = true;
        break; // should exit here after the first iteration
    }
}
---

output:

---
loop: 0 0
loop: 1 1
core.exception.AssertError@test(12): Assertion failure
---

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 27, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4131


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #1 from bearophile_hugs@eml.cc 2010-04-27 15:39:44 PDT ---
This bug is present in dmd 2.043, and it's absent in dmd 1.058 and 1.042.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 28, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4131


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au
            Version|unspecified                 |2.040
           Severity|normal                      |regression


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 30, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4131


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2010-04-29 22:13:36 PDT ---
changeset druntime 287

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 06, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4131


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #3 from Don <clugdbug@yahoo.com.au> 2010-05-05 19:12:56 PDT ---
Fixed DMD2.044

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