[swift-evolution] Change `repeat` to loop indefinitely if no while clause is present

Tyler Cloutier cloutiertyler at aol.com
Tue May 10 16:27:43 CDT 2016


> On May 10, 2016, at 2:13 PM, Harlan Haskins via swift-evolution <swift-evolution at swift.org> wrote:
> 
> You could always do your control flow with goto’s anyway…
> 
> func foo() {
>   var i = 0
>   func goto(_ label: String = "entry") {
>     switch label {
>     case "entry":
>       print("beginning loop…")
>       goto("cond")
>     case "cond":
>       goto(i < 10 ? "body" : "end")
>     case "body":
>       i += 1
>       print("\(i)")
>       goto("cond")
>     case "end":
>       break
>     default: break
>     }
>   }
>   goto()
> }
> 
> Apologies,
> Harlan


And isn’t this the point really. Yes there are many different ways of doing something, but there should be one obvious way. IMHO, there is nothing more obvious than just 

repeat {

}

It’s very clear. It’s not about adding complex control flow, it’s about simplifying current syntax. I don’t think anyone is arguing that it’s more powerful than what while loops currently offer.


> 
>> On May 10, 2016, at 2:05 PM, Taras Zakharko via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> When I need a loop with complex control flow that does not fit into the classical while {} or repeat {} while structure, I use this:
>> 
>> do_stuff: do {
>>>>  continue do_stuff
>> } 
>> 
>> This pattern explicit and allows very complex control flow patterns without the drawbacks of the unrestricted goto construct. 
>> 
>> Therefore I don’t see utility with having a repeat {} without while clause. 
>> 
>> Best, 
>> 
>> Taras
>> 
>> 
>>> On 10 May 2016, at 22:39, Dominik Pich via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> 
>>> 
>>>>> On May 10, 2016, at 3:30 PM, Tyler Cloutier via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>>> 
>>>>> Secondly it’s a very simple way of introducing new programmers to loops. It’s IMHO more clear to a new programmer that repeat will just repeat indefinitely vs while true.
>>>> 
>>>> This point seems strange to me - why teach a new programmer about loops by first showing them a looping construct they should probably never use in actual practice until they really know what they’re doing?
>>> totally agree… it would be a bad first introduction, id say :)
>>> 
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160510/502ddc00/attachment.html>


More information about the swift-evolution mailing list