title: Swift - Prevent function from being called twice
body: <p>My main code is to long to put here so i'll try with a simpler explanation. Let's say i have a global variable called "count" that gets used by functions. If count was to get called twice for w.e reason as shown in the code below... how can i make it so the output "10 , 10" rather then "10 , 20".</p>
  
  <pre><code>var count = 0
  
  override func viewDidLoad() {
  
    helloWorld()
  
  }
  
  
  override func viewWillAppear(_ animated: Bool) {
      helloWorld()
  }
  
  
  
  func helloWorld(){
      var counter = 0
      for i in 1...10{
          count = count + 1
          counter = counter + 1
      }
      print(count)
  }
  </code></pre>