I was serious this time and the first time (years ago now) that this came
up. My motivation was not really core to the Go manifesto; in addition to
all the good Go usage model things, I also like using it to teach or show
algorithms. In this use I wanted to be able to naturally present both:

while (condition) do {stuff} // aka, for

and

do {stuff} while (condition)

It comes up in function approximation, linked list traversal, and many
computer science situations. As has been pointed out, it is clear how to
achieve the second with the first using tests in side an infinite loop. I
do it enough that it is "natural" to work around the issue. That does not
make the code natural though. It is a workaround and that's what appears in
the text. I don't like that so I use go-like pseudocode.

That's ok. I still love Go for what it is good at.

Michael

On Wed, May 9, 2018 at 3:59 PM <matthewju...@gmail.com> wrote:

> I’m not sure if C has been directly mentioned. I started with C so
> iteration is just a nice shortcut to me. Assuming you’ve always had
> collection iteration available an explanation is the for loop can make the
> useful pattern of indexing into an array up to the length of the array
> using an index variable.
>
> s := [5]int{0, 1, 2, 3, 4}
> // this C-style iteration prints 12345
> for i := 0; i < len(s); i++ {
>     fmt.Print(s[i]+1)
> }
>
> Coming from C it makes sense to me to combine all looping, including
> collection iteration, into one keyword. For, while, and do-while all look
> the same to me.
>
> Matt
>
> On Wednesday, May 9, 2018 at 4:26:44 PM UTC-5, Hugh Fisher wrote:
>>
>>
>>
>> On Thursday, May 10, 2018 at 4:20:41 AM UTC+10, Marc wrote:
>>>
>>> I'm still not convinced this topic is not some kind of elaborate joke.
>>>
>>
>> It's certainly diverged from my original post, which is why I'm staying
>> quiet.
>>
>> cheers,
>> Hugh Fisher
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Michael T. Jones
michael.jo...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to