duangan6731 2013-05-03 06:31
浏览 35
已采纳

如何在不使用循环变量的情况下为循环建立刻度线

I have a for loop that continually runs over an interval, however I am only using it as a function that I want running every 10 Minutes. How can I declare this for-loop without having to use 'x' somewhere inside of the loop

interval := time.Tick(10 * time.Minute)

for x := range interval {
  ...code that does not use x
}

I have tried restructuring the for loop but nothing results in it running without specifically using 'x', I know I could just simply do something with 'x' inside of the loop, but I would rather learn how to properly implement this for loop then make a hack.

  • 写回答

3条回答 默认 最新

  • dragon2025 2013-05-03 06:34
    关注

    Either

    for {
            <-time.After(someTime)
            // ...
    }
    

    or

    interval := time.Tick(someTime)
    
    for ; ; <-interval { // First interval == 0
            // ...
    }
    

    or

    interval := time.Tick(someTime)
    
    for {
            <-interval
            // ...
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部