for v := range values { funcs = append(funcs, func() { fmt.Println(v) }) }
for _, f := range funcs { f() } }
Варианты ответа: A)
1 2
B)
2 2
C)
20 30
D)
0 0
---
✅ Правильный ответ: A
Почему: В Go 1.24 при использовании for v := range, переменная v копируется на каждой итерации, а не переиспользуется. Таким образом, замыкания получают своё собственное значение v на каждой итерации. Здесь range возвращает индексы (0, 1, 2), а не значения среза.
Чтобы получить значения (10, 20, 30), нужно использовать for _, v := range values.
for v := range values { funcs = append(funcs, func() { fmt.Println(v) }) }
for _, f := range funcs { f() } }
Варианты ответа: A)
1 2
B)
2 2
C)
20 30
D)
0 0
---
✅ Правильный ответ: A
Почему: В Go 1.24 при использовании for v := range, переменная v копируется на каждой итерации, а не переиспользуется. Таким образом, замыкания получают своё собственное значение v на каждой итерации. Здесь range возвращает индексы (0, 1, 2), а не значения среза.
Чтобы получить значения (10, 20, 30), нужно использовать for _, v := range values.
The channel also called on people to turn out for illegal assemblies and listed the things that participants should bring along with them, showing prior planning was in the works for riots. The messages also incited people to hurl toxic gas bombs at police and MTR stations, he added. Telegram is a leading cloud-based instant messages platform. It became popular in recent years for its privacy, speed, voice and video quality, and other unmatched features over its main competitor Whatsapp. With Bitcoin down 30% in the past week, some crypto traders have taken to Telegram to “voice” their feelings. Click “Save” ; The optimal dimension of the avatar on Telegram is 512px by 512px, and it’s recommended to use PNG format to deliver an unpixelated avatar.
from us