# Pre-RFC: Break with value in for/while loops

**URL:** <https://internals.rust-lang.org/t/pre-rfc-break-with-value-in-for-while-loops/11208>\
**Category:** Uncategorized\
**Created:** [October 30, 2019, 1:28pm UTC](https://internals.rust-lang.org/t/pre-rfc-break-with-value-in-for-while-loops/11208 "2019-10-30T13:28:04Z")\
**Posts on this page:** 1\
**Showing post:** 75

<div class="post-metadata">

**Author:** ![newpavlov](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/newpavlov/32/3290_2.png) [@newpavlov](https://internals.rust-lang.org/u/newpavlov)\
**Post date:** [February 11, 2020, 1:01am UTC](https://internals.rust-lang.org/t/pre-rfc-break-with-value-in-for-while-loops/11208/75 "2020-02-11T01:01:44Z")

</div>

> [@kennytm](#):
>
> generator is the next best solution, but it doesn't cover `while` and are too experimental to rely on.

Personally as a proponent of the generator approach I don't care about value `break`s that much. In practice I can't remember many cases of when I needed such feature. But I really hope that [integration](https://internals.rust-lang.org/t/6625) of generators into `for` loops will help with the following pattern which is annoyingly common:

```rust
for value in iter {
    let value = value?;
    // ...
}

```

It even causes ad-hoc proposals like `for val? in iter { .. }` instead f a more generic solution. Allowing value `break`s is just a nice bonus.

Note that iteration over `Iterator<Item=Result<T, E>>` has different semantics from iteration over `Generator<Yield=T, Return=Result<(), E>>`. In the former case you may receive `Ok` values after an error, but in the latter one the iteration must be terminated on a first error. (Unfortunately we do not enforce this constraint using type system, but it's a different discussion...)

---

_[View the full topic](https://internals.rust-lang.org/t/pre-rfc-break-with-value-in-for-while-loops/11208)._
