On Fri, Dec 24, 2021 at 9:38 AM Kevin Chowski <ke...@chowski.com> wrote:
>
> On Friday, December 24, 2021 at 10:08:23 AM UTC-7 cuiw...@gmail.com wrote:
>>
>> does the range expr will be evaluated means when range expr is slice, the 
>> slice header will be copy, and when range expr is array, array will be coy?
>
>
> I believe this is true, but I don't quite know why it is guaranteed in the 
> specification. Someone else may be able answer this question with more 
> evidence.

Yes, the slice header or the entire array will be copied when the loop
starts (at least conceptually copied--the compiler can eliminate the
actual copy if it doesn't make any difference).  This clarifies what
happens if the range loop changes the slice or array during the loop.

Ian

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUh6tJ%3DFNx_PyKfxCejvW4cUFbwd1nyP1vjGTfZQ9oyqw%40mail.gmail.com.

Reply via email to