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

           Summary: Feature Request: while-else
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: yanik...@gmail.com


--- Comment #0 from ibrahim YANIKLAR <yanik...@gmail.com> 2010-01-12 08:39:50 
PST ---
It would be nice to add a while-else statement to the language.

while ( Expression1 )
    ScopeStatement1
else
    ScopeStatement2

may act like that:

if ( Expression1 )
    do
        ScopeStatement1
    while ( Expression1 );
else
    ScopeStatement2

or like that:

bool entered = false;

while ( Expression1 )
{
    entered = true;
    ScopeStatement1
}

if (!entered)
    ScopeStatement2


two of them has some problems. 
First one is more efficient but you must write the same expression twice.
The second is more readable but there is an extra declaration and an extra
cost.

while-else is more readable and more efficient. 

someone can want a python like while-else statement.
using while-finally syntax would be more suitable for that.

while ( ... )
{
    ...
    if ( ... )
       break;
    ...
}
finally
    ScopeStatement3
...

if break occures the ScopeStatement3 is not executed else it is executed once.
But I think it is not necessary because we can provide that by using a simple
goto statement instead of break. 

while ( ... )
{
    ...
    if ( ... )
       goto label;
    ...
}

ScopeStatement3

label:
...

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

Reply via email to