Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support else statements for for loops #27

Open
mrwright opened this issue Jun 17, 2014 · 5 comments
Open

Support else statements for for loops #27

mrwright opened this issue Jun 17, 2014 · 5 comments
Labels

Comments

@mrwright
Copy link
Member

No description provided.

@gwillen
Copy link

gwillen commented Jun 17, 2014

Under what circumstances does the 'else' execute? I always found the concept of an 'else' on a loop to be unclear. Is it if we break, or if the condition becomes false (i.e. we don't break), or if the loop body doesn't execute at all?

@mrwright
Copy link
Member Author

I was thinking that they would act as they do in Python; see here. The summary:

it is executed when the loop terminates through exhaustion of the list (with for) or when the condition becomes false (with while), but not when the loop is terminated by a break statement.

This is useful when searching for something with a loop; if you find it you break; if you fail, you run the else statement.

@gwillen
Copy link

gwillen commented Jun 17, 2014

Okay, I do see why that's useful. Is there a more clever name for it than 'else'?

@jwise
Copy link

jwise commented Jan 3, 2018

Yes. Clearly, it should be:

for (INIT-EXPRESSION; COND-EXPRESSION; LOOP-EXPRESSION)
  STATEMENT
rof
  STATEMENT

@mrwright
Copy link
Member Author

mrwright commented Mar 16, 2020

On IRC there was a suggestion of separate keywords for the two cases--perhaps broken and completed. (And it seems fine to allow either, none, or both, in any order, for a particular for loop.)

I think this would also allow for loops to be used as expressions (though any for loop of non-unit type would need to specify both extra clauses).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants