Details
-
Type:
New Feature
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 0.8.1
-
Fix Version/s: 0.8.2
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
for <target_list> in <enumerable>: <for_block> else: <else_block>
<else_block> is only executed when the loop terminates because <enumerable>.MoveNext() returns false when evaluated, i.e. whenever the <enumerable> attempts to move to the next item, but the <enumerable> is exhausted. This also means that if <enumerable> has no item at the first 'iteration', <enumerable>.MoveNext() will return false, and the <else_block> will be executed.
while <expression>: <while_block> else: <else_block>
<else_block> is only executed when the loop terminates the <expression> is tested but resolves to a false, null, or 0 value. This also means that if <expression> is false the first time it is tested (even before entering <while_block>) <else_block> will be executed.
The effect is that for these loops, <else_block> will not be executed when execution leaves the loop due to a break, raise, or return because <expression>/<enumerable>.MoveNext() is not evaluated. Note that the cause of the <else-block> executing is the condition evaluating to false.
This change should be minimally invasive, and as it adds to the language without adversely increasing complexity, I have no problems with it being implemented.