Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

for loop - How to increase or modify the index inside a range

I iterate inside an array by using for-each range for Go. It works fine. But the problem is at some conditions I want to modify the index such like adding by 2 or more. How I can fix that problem? You can find out the sample code below.

for index,_ := range c {
      if  index < len(c)-2 && c[index  + 2]  == 0 {
        index = index + 1
        numberOfJumps++
    } else if index < len(c) - 1 && c[index + 1] == 0  {
        numberOfJumps++
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...