Sorry, my example should have been the other way around:
var data: NSData!
for 1...5 {
data = self.loadSomeData()
if data != nil {
break // *this* can't be done with .forEach
}
/// Try again in next iteration
}
if data == nil {
`continue` can be rewritten `return` inside `forEach`.
On Tue, Jul 5, 2016 at 02:30 Charlie Monroe via swift-evolution <
swift-evolution@swift.org> wrote:
> Example:
>
> for 1...5 {
> guard let data = self.loadSomeData() else {
> /// Will try it several times and then report failure to the user.
Example:
for 1...5 {
guard let data = self.loadSomeData() else {
/// Will try it several times and then report failure to the
user.
continue
}
// process data
return
}
// Error, failed to load data even after retrying.
>
How would you build a condition to break if you are ignoring each value ?
Unless you are hard coding a condition in which case I would still argue that
the proposed shorthand for is less clear than `for _ in` or forEach.
> On Jul 4, 2016, at 9:29 PM, Charlie Monroe
> -1 this is why we have collection.forEach{}
>
> (1...10).forEach {
> // do something.
> }
This is not equivalent since it doesn't allow you to break from the for loop.
>
> On Jul 1, 2016, at 12:38 AM, Diego Barros via swift-evolution
>
> On Jul 4, 2016, at 2:39 PM, Karl Wagner via swift-evolution
> wrote:
>
> -1. I like the underscore. If it turns out you do need the loop variable
> later, it's easy to see where to add it.
>
> Karl
-1 I agree with this and doing something a specific number of
-1. I like the underscore. If it turns out you do need the loop variable later,
it's easy to see where to add it.
Karl
>
> On Jul 1, 2016 at 9:38 AM, (mailto:swift-evolution@swift.org)> wrote:
>
>
>
>
> When you want a simple `for` loop, for example:
>
>
>
>
-1 this is why we have collection.forEach{}
(1...10).forEach {
// do something.
}
> On Jul 1, 2016, at 12:38 AM, Diego Barros via swift-evolution
> wrote:
>
> When you want a simple `for` loop, for example:
>
> for _ in 1...10 {
>
> // do something 10 times
>
>
+1 on anything that removes underscores ;-)
___
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
> On 2 Jul 2016, at 14:19, Anton Zhilin via swift-evolution
> wrote:
>
> Diego Barros via swift-evolution writes:
>
>> for 1...10 {
>> // do something 10 times
>> }
>
> Firstly, this should be delayed to post-Swift 3.
> Secondly, I tend to
Minor, but I think I'd be onboard as well. Once proposed (and assuming it was
approved), this would likely be deferred until post Swift 3 since it’s additive.
l8r
Sean
> On Jul 1, 2016, at 2:38 AM, Diego Barros via swift-evolution
> wrote:
>
> When you want a
+1, having to add an underscore in a X.times loop always feels contrived.
On Fri, Jul 1, 2016 at 2:38 AM, Diego Barros via swift-evolution <
swift-evolution@swift.org> wrote:
> When you want a simple `for` loop, for example:
>
> for _ in 1...10 {
>
> // do something 10 times
>
> }
>
>
> Clean-up
Additive idea, but +1 for looping on ranges without the need on an index.
--
Adrian Zubarev
Sent with Airmail
Am 1. Juli 2016 um 09:39:23, Diego Barros via swift-evolution
(swift-evolution@swift.org) schrieb:
When you want a simple `for` loop, for example:
for _ in 1...10 {
// do
When you want a simple `for` loop, for example:
for _ in 1...10 {
// do something 10 times
}
Clean-up and simplify the syntax by removing the superfluous underscore and
`in`:
for 1...10 {
// do something 10 times
}
-- diego
___
swift-evolution
14 matches
Mail list logo