O
O
onlinejunior2020-05-17 21:23:58
go
onlinejunior, 2020-05-17 21:23:58

How to open a function every X times?

Let's say I want to create a new file when 2k numbers are reached.

package main

import (
        "fmt"
  "log"
)

var start, end, split, i = 1, start+1000, 10000, 0

func main() {
  fmt.Println("Enter: start, end, split")
  fmt.Scanf("%d %d %d", &start, &end, &split )

  for i := 0; i < split/1000; i++ {

    for j := start; j < end; j++ {
      //start отвечает за стартовую позицию генерации чисел
      //end отвечает за конечную позицию генерации чисел

    }
                 
                //достигли 2, 4, 6, 8, 10 - открываем функцию
                //шаг позиции 1000
    log.Printf("STEP: %d | %d - %d", end-start, start, end)
    start, end = end+1, end+1001
  }
}


https://play.golang.org/p/meA-ylef_Pj

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pavlyuk, 2020-05-17
@pav5000

If the numbers are in order, then you just need to consider the remainder of dividing the number by 2000.
if i % 2000 == 0 {....}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question