咨询一个循环问题:

hellsam · · 802 次点击
package main import "fmt" func main() { new_start := 2 new_end := 6 old_start := 4 old_end := 8 for i := new_start; i <= new_end; i++ { // 计算 j 的偏移量,使其与 i 对应 offset := i - new_start j := old_start + offset if j > old_end { break // 避免 j 超过 old_end } fmt.Println(i, ":", j) } }
#3
更多评论
![7EC2BF62-9F17-4957-8953-E7FB202471AF.png](https://static.golangjob.cn/231214/8f8af649fc8dc4234a55232a81fc6728.png)
#2