Skip to content

Commit

Permalink
Update for_expr docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonson committed Sep 7, 2013
1 parent 25f3b29 commit 8f31377
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions doc/rust.md
Expand Up @@ -2459,25 +2459,12 @@ do k(3) |j| {
### For expressions

~~~~~~~~{.ebnf .gram}
for_expr : "for" expr [ '|' ident_list '|' ] ? '{' block '}' ;
for_expr : "for" pat "in" expr '{' block '}' ;
~~~~~~~~

A _for expression_ is similar to a [`do` expression](#do-expressions),
in that it provides a special block-form of lambda expression,
suited to passing the `block` function to a higher-order function implementing a loop.

In contrast to a `do` expression, a `for` expression is designed to work
with methods such as `each` and `times`, that require the body block to
return a boolean. The `for` expression accommodates this by implicitly
returning `true` at the end of each block, unless a `break` expression
is evaluated.

In addition, [`break`](#break-expressions) and [`loop`](#loop-expressions) expressions
are rewritten inside `for` expressions in the same way that `return` expressions are,
with a combination of local flag variables,
and early boolean-valued returns from the `block` function,
such that the meaning of `break` and `loop` is preserved in a primitive loop
when rewritten as a `for` loop controlled by a higher order function.
A `for` expression is a syntactic construct for looping
over elements provided by an implementation of
`std::iterator::Iterator`.

An example of a for loop over the contents of a vector:

Expand Down

5 comments on commit 8f31377

@bors
Copy link
Contributor

@bors bors commented on 8f31377 Sep 11, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from thestinger
at brandonson@8f31377

@bors
Copy link
Contributor

@bors bors commented on 8f31377 Sep 11, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging singingboyo/rust/update-for-expr-docs = 8f31377 into auto

@bors
Copy link
Contributor

@bors bors commented on 8f31377 Sep 11, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

singingboyo/rust/update-for-expr-docs = 8f31377 merged ok, testing candidate = 49eb7bd

@bors
Copy link
Contributor

@bors bors commented on 8f31377 Sep 11, 2013

@bors
Copy link
Contributor

@bors bors commented on 8f31377 Sep 11, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 49eb7bd

Please sign in to comment.